lib/origen/sub_blocks.rb in origen-0.42.0 vs lib/origen/sub_blocks.rb in origen-0.42.1

- old
+ new

@@ -269,11 +269,13 @@ def has_tests? tests.empty? ? false : true end - def sub_block(name, options = {}) + def sub_block(name = nil, options = {}) + name, options = nil, name if name.is_a?(Hash) + return sub_blocks unless name if i = options.delete(:instances) # permit creating multiple instances of a particular sub_block class # can pass array for base_address, which will be processed above Origen.deprecate 'instances: option to sub_block is deprecated, use sub_block_groups instead' group_name = name =~ /s$/ ? name : "#{name}s" # take care if name already with 's' is passed @@ -293,15 +295,17 @@ # there are probably a lot more corner-cases to consider, and hopefully no one will # really need this anyway. if sub_blocks[name] && !sub_blocks[name].is_a?(Placeholder) fail "You have already defined a sub-block named #{name} within class #{self.class}" end - unless respond_to?(name) - define_singleton_method name do - get_sub_block(name) - end + if respond_to?(name) + callers = caller[0].split(':') + Origen.log.warning "The sub_block defined at #{Pathname.new(callers[0]).relative_path_from(Pathname.pwd)}:#{callers[1]} is overriding an existing method called #{name}" end + define_singleton_method name do + get_sub_block(name) + end if sub_blocks[name] && sub_blocks[name].is_a?(Placeholder) sub_blocks[name].add_attributes(options) else sub_blocks[name] = block end @@ -345,9 +349,13 @@ # def sub_block_group(id, options = {}) @current_group = [] # open group yield # any sub_block calls within this block will have their ID added to @current_group my_group = @current_group.dup + if respond_to?(id) + callers = caller[0].split(':') + Origen.log.warning "The sub_block_group defined at #{Pathname.new(callers[0]).relative_path_from(Pathname.pwd)}:#{callers[1]} is overriding an existing method called #{id}" + end define_singleton_method "#{id}" do if options[:class_name] b = Object.const_get(options[:class_name]).new else b = []