lib/configure_me/nesting.rb in configure_me-0.5.0 vs lib/configure_me/nesting.rb in configure_me-0.6.0

- old
+ new

@@ -1,42 +1,48 @@ module ConfigureMe - class Base - class << self + module Nesting + extend ActiveSupport::Concern + + module ClassMethods def nest_me(klass, name = nil) - klass.instance.nest(self) + klass.nested_classes[self.config_name.to_sym] = self + klass.class_eval <<-EOF, __FILE__, __LINE__ + def #{self.config_name} + @#{self.config_name} ||= begin + config = self.class.nested_classes["#{self.config_name}".to_sym].new + config.parent_config = self + self.children["#{self.config_name}".to_sym] = config + config + end + end + EOF end - end - end - module Nesting - - def nest(klass) - children[klass.instance.config_name.to_sym] = klass.instance - klass.instance.parent_config = self - self.class_eval <<-EOF, __FILE__, __LINE__ - def #{klass.instance.config_name} - children[:#{klass.instance.config_name.to_s}] - end - EOF + def nested_classes + @nested_classes ||= {} + end end - def parent_config - @parent_config ||= nil - end + module InstanceMethods - def parent_config=(parent_config) - @parent_config = parent_config - end + def parent_config + @parent_config ||= nil + end - def children - @children ||= {} - end + def parent_config=(parent_config) + @parent_config = parent_config + end - def all_configs - res = [self] - children.values.each do |child| - res.concat(child.all_configs) + def children + @children ||= {} end - res + + def all_configs + res = [self] + children.values.each do |child| + res.concat(child.all_configs) + end + res + end end end end