lib/configure_me/nesting.rb in configure_me-0.3.2 vs lib/configure_me/nesting.rb in configure_me-0.4.0

- old
+ new

@@ -1,36 +1,42 @@ -require 'active_support/concern' - module ConfigureMe - module Nesting - extend ActiveSupport::Concern - - included do - @@nested = [] - end - - module ClassMethods + class Base + class << self def nest_me(klass, name = nil) - klass.nest(self) - @nested_name = name || klass.config_name + klass.instance.nest(self) end - - def nested - @nested ||= [] - end - - def nest(klass) - nested << klass - end end + end + module Nesting + def nest(klass) - @children[klass.config_name] = klass.instance - klass.instance.parent = self + children[klass.instance.config_name.to_sym] = klass.instance + klass.instance.parent_config = self self.class_eval <<-EOF, __FILE__, __LINE__ - def #{klass.config_name} - @children['#{klass.config_name}'] + def #{klass.instance.config_name} + children[:#{klass.instance.config_name.to_s}] end EOF + end + + def parent_config + @parent_config ||= nil + end + + def parent_config=(parent_config) + @parent_config = parent_config + end + + def children + @children ||= {} + end + + def all_configs + res = [self] + children.values.each do |child| + res.concat(child.all_configs) + end + res end end end