Class: Origen::SubBlocks::Placeholder

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/sub_blocks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, attributes) ⇒ Placeholder

Returns a new instance of Placeholder


332
333
334
335
336
# File 'lib/origen/sub_blocks.rb', line 332

def initialize(owner, name, attributes)
  @owner = owner
  @name = name
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


357
358
359
# File 'lib/origen/sub_blocks.rb', line 357

def method_missing(method, *args, &block)
  materialize.send(method, *args, &block)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes


330
331
332
# File 'lib/origen/sub_blocks.rb', line 330

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name


330
331
332
# File 'lib/origen/sub_blocks.rb', line 330

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner


330
331
332
# File 'lib/origen/sub_blocks.rb', line 330

def owner
  @owner
end

Instance Method Details

#==(obj) ⇒ Object Also known as: equal?


377
378
379
380
381
382
383
# File 'lib/origen/sub_blocks.rb', line 377

def ==(obj)
  if obj.is_a?(Placeholder)
    materialize == obj.materialize
  else
    materialize == obj
  end
end

#add_attributes(attrs) ⇒ Object


338
339
340
# File 'lib/origen/sub_blocks.rb', line 338

def add_attributes(attrs)
  @attributes = @attributes.merge(attrs)
end

#classObject

Make this appear like a sub-block to any application code


343
344
345
# File 'lib/origen/sub_blocks.rb', line 343

def class
  klass
end

#cloneObject


390
391
392
# File 'lib/origen/sub_blocks.rb', line 390

def clone
  materialize.clone
end

#dupObject


394
395
396
# File 'lib/origen/sub_blocks.rb', line 394

def dup
  materialize.dup
end

#freezeObject


386
387
388
# File 'lib/origen/sub_blocks.rb', line 386

def freeze
  materialize.freeze
end

#inspectObject

Make it look like a sub-block in the console to avoid confusion


353
354
355
# File 'lib/origen/sub_blocks.rb', line 353

def inspect
  "<SubBlock: #{name}>"
end

#is_a?(klass) ⇒ Boolean

Make this appear like a sub-block to any application code

Returns:

  • (Boolean)

348
349
350
# File 'lib/origen/sub_blocks.rb', line 348

def is_a?(klass)
  klass == self.klass || klass == Placeholder
end

#klassObject


402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/origen/sub_blocks.rb', line 402

def klass
  @klass ||= begin
    class_name = attributes.delete(:class_name)
    if class_name
      if eval("defined? ::#{owner.namespace}::#{class_name}")
        klass = eval("::#{owner.namespace}::#{class_name}")
      else
        if eval("defined? #{class_name}")
          klass = eval(class_name)
        else
          if eval("defined? #{owner.class}::#{class_name}")
            klass = eval("#{owner.class}::#{class_name}")
          else
            puts "Could not find class: #{class_name}"
            fail 'Unknown sub block class!'
          end
        end
      end
    else
      klass = Origen::SubBlock
    end
    unless klass.respond_to?(:includes_origen_model)
      puts 'Any class which is to be instantiated as a sub_block must include Origen::Model,'
      puts "add this to #{klass}:"
      puts ''
      puts '  include Origen::Model'
      puts ''
      fail 'Sub block does not include Origen::Model!'
    end
    klass
  end
end

#materializeObject


365
366
367
368
369
370
371
372
373
374
375
# File 'lib/origen/sub_blocks.rb', line 365

def materialize
  file = attributes.delete(:file)
  dir = attributes.delete(:dir) || owner.send(:export_dir)
  block = owner.send(:instantiate_sub_block, name, klass, attributes)
  if file
    require File.join(dir, file)
    block.extend owner.send(:export_module_names_from_path, file).join('::').constantize
  end
  block.owner = owner
  block
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

361
362
363
# File 'lib/origen/sub_blocks.rb', line 361

def respond_to?(method, include_private = false)
  materialize.respond_to?(method, include_private)
end

#to_json(*args) ⇒ Object


398
399
400
# File 'lib/origen/sub_blocks.rb', line 398

def to_json(*args)
  materialize.to_json(*args)
end