Class: Origen::SubBlocks::Placeholder
- Inherits:
-
Object
- Object
- Origen::SubBlocks::Placeholder
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.
415
416
417
418
419
|
# File 'lib/origen/sub_blocks.rb', line 415
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
445
446
447
|
# File 'lib/origen/sub_blocks.rb', line 445
def method_missing(method, *args, &block)
materialize.send(method, *args, &block)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
413
414
415
|
# File 'lib/origen/sub_blocks.rb', line 413
def attributes
@attributes
end
|
Returns the value of attribute name.
413
414
415
|
# File 'lib/origen/sub_blocks.rb', line 413
def name
@name
end
|
Returns the value of attribute owner.
413
414
415
|
# File 'lib/origen/sub_blocks.rb', line 413
def owner
@owner
end
|
Instance Method Details
#==(obj) ⇒ Object
Also known as:
equal?
468
469
470
471
472
473
474
|
# File 'lib/origen/sub_blocks.rb', line 468
def ==(obj)
if obj.is_a?(Placeholder)
materialize == obj.materialize
else
materialize == obj
end
end
|
#add_attributes(attrs) ⇒ Object
421
422
423
|
# File 'lib/origen/sub_blocks.rb', line 421
def add_attributes(attrs)
@attributes = @attributes.merge(attrs)
end
|
Make this appear like a sub-block to any application code
426
427
428
|
# File 'lib/origen/sub_blocks.rb', line 426
def class
klass
end
|
481
482
483
|
# File 'lib/origen/sub_blocks.rb', line 481
def clone
materialize.clone
end
|
485
486
487
|
# File 'lib/origen/sub_blocks.rb', line 485
def dup
materialize.dup
end
|
477
478
479
|
# File 'lib/origen/sub_blocks.rb', line 477
def freeze
materialize.freeze
end
|
Make it look like a sub-block in the console to avoid confusion
441
442
443
|
# File 'lib/origen/sub_blocks.rb', line 441
def inspect
"<SubBlock: #{name}>"
end
|
#is_a?(klass) ⇒ Boolean
Make this appear like a sub-block to any application code
431
432
433
434
435
436
437
438
|
# File 'lib/origen/sub_blocks.rb', line 431
def is_a?(klass)
return false if klass == Hash || klass == Array
klass == self.klass || klass == Placeholder
end
|
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
# File 'lib/origen/sub_blocks.rb', line 493
def klass
@klass ||= begin
class_name = attributes.delete(:class_name)
tmp_class = nil
if class_name
begin
tmp_class = "::#{owner.namespace}::#{class_name}"
klass = eval(tmp_class)
rescue NameError => e
raise if e.message !~ /^uninitialized constant (.*)$/ || tmp_class !~ /#{Regexp.last_match(1)}/
begin
tmp_class = "::#{class_name}"
klass = eval(tmp_class)
rescue NameError => e
raise if e.message !~ /^uninitialized constant (.*)$/ || tmp_class !~ /#{Regexp.last_match(1)}/
begin
tmp_class = "#{owner.class}::#{class_name}"
klass = eval(tmp_class)
rescue NameError => e
raise if e.message !~ /^uninitialized constant (.*)$/ || tmp_class !~ /#{Regexp.last_match(1)}/
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
|
#materialize ⇒ Object
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
# File 'lib/origen/sub_blocks.rb', line 453
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
449
450
451
|
# File 'lib/origen/sub_blocks.rb', line 449
def respond_to?(method, include_private = false)
materialize.respond_to?(method, include_private)
end
|
#to_json(*args) ⇒ Object
489
490
491
|
# File 'lib/origen/sub_blocks.rb', line 489
def to_json(*args)
materialize.to_json(*args)
end
|