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



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

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



423
424
425
# File 'lib/origen/sub_blocks.rb', line 423

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes



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

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name



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

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner



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

def owner
  @owner
end

Instance Method Details

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



446
447
448
449
450
451
452
# File 'lib/origen/sub_blocks.rb', line 446

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

#add_attributes(attrs) ⇒ Object



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

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

#classObject

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



404
405
406
# File 'lib/origen/sub_blocks.rb', line 404

def class
  klass
end

#cloneObject



459
460
461
# File 'lib/origen/sub_blocks.rb', line 459

def clone
  materialize.clone
end

#dupObject



463
464
465
# File 'lib/origen/sub_blocks.rb', line 463

def dup
  materialize.dup
end

#freezeObject



455
456
457
# File 'lib/origen/sub_blocks.rb', line 455

def freeze
  materialize.freeze
end

#inspectObject

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



419
420
421
# File 'lib/origen/sub_blocks.rb', line 419

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

#is_a?(klass) ⇒ Boolean

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

Returns:

  • (Boolean)


409
410
411
412
413
414
415
416
# File 'lib/origen/sub_blocks.rb', line 409

def is_a?(klass)
  # Because sub_blocks are stored in a hash.with_indifferent_access, the value is tested
  # against being a Hash or Array when it is added to the hash. This prevents the class being
  # looking up and loaded by the autoload system straight away, especially if the sub-block
  # has been specified to lazy load
  return false if klass == Hash || klass == Array
  klass == self.klass || klass == Placeholder
end

#klassObject



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/origen/sub_blocks.rb', line 471

def klass
  @klass ||= begin
    class_name = attributes.delete(:class_name)
    if class_name
      begin
        klass = eval("::#{owner.namespace}::#{class_name}")
      rescue NameError
        begin
          klass = eval(class_name)
        rescue NameError
          begin
            klass = eval("#{owner.class}::#{class_name}")
          rescue NameError
            puts "Could not find class: #{class_name}"
            raise '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



431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/origen/sub_blocks.rb', line 431

def materialize
  block = nil
  file = attributes.delete(:file)
  load_block = attributes.delete(:load_block)
  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.load_block(load_block) if load_block
  block.owner = owner
  block
end

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

Returns:

  • (Boolean)


427
428
429
# File 'lib/origen/sub_blocks.rb', line 427

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

#to_json(*args) ⇒ Object



467
468
469
# File 'lib/origen/sub_blocks.rb', line 467

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