lib/configure_me/nesting.rb in configure_me-0.6.0 vs lib/configure_me/nesting.rb in configure_me-0.6.1
- old
+ new
@@ -3,34 +3,38 @@
extend ActiveSupport::Concern
module ClassMethods
def nest_me(klass, name = nil)
klass.nested_classes[self.config_name.to_sym] = self
+ self.parent_config_klass = klass
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
def nested_classes
@nested_classes ||= {}
end
+
+ def parent_config_klass
+ @parent_config_klass ||= nil
+ end
+
+ def parent_config_klass=(parent_config_klass)
+ @parent_config_klass = parent_config_klass
+ end
end
module InstanceMethods
def parent_config
- @parent_config ||= nil
- end
-
- def parent_config=(parent_config)
- @parent_config = parent_config
+ self.class.parent_config_klass ? self.class.parent_config_klass.new : nil
end
def children
@children ||= {}
end