lib/origen/sub_blocks.rb in origen-0.44.0 vs lib/origen/sub_blocks.rb in origen-0.50.0

- old
+ new

@@ -405,10 +405,15 @@ klass end # Make this appear like a sub-block to any application code 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 # Make it look like a sub-block in the console to avoid confusion def inspect @@ -422,17 +427,20 @@ def respond_to?(method, include_private = false) materialize.respond_to?(method, include_private) end 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 def ==(obj) @@ -462,21 +470,21 @@ def klass @klass ||= begin class_name = attributes.delete(:class_name) if class_name - if eval("defined? ::#{owner.namespace}::#{class_name}") + begin klass = eval("::#{owner.namespace}::#{class_name}") - else - if eval("defined? #{class_name}") + rescue NameError + begin klass = eval(class_name) - else - if eval("defined? #{owner.class}::#{class_name}") + rescue NameError + begin klass = eval("#{owner.class}::#{class_name}") - else + rescue NameError puts "Could not find class: #{class_name}" - fail 'Unknown sub block class!' + raise 'Unknown sub block class!' end end end else klass = Origen::SubBlock @@ -499,9 +507,15 @@ # defined without another class name specified # # This class includes support for registers, pins, etc. class SubBlock include Origen::Model + + # Since no application defined this sub-block class, consider its parent's app to be + # the owning application + def app + parent.app + end # Used to create attribute accessors on the fly. # # On first call of a missing method a method is generated to avoid the missing lookup # next time, this should be faster for repeated lookups of the same method, e.g. reg