Module: ConfigureMe::Nesting::ClassMethods

Defined in:
lib/configure_me/nesting.rb

Instance Method Summary collapse

Instance Method Details

#nest_me(klass, name = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/configure_me/nesting.rb', line 6

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
        self.children["#{self.config_name}".to_sym] = config
        config
      end
    end
  EOF
end

#nested_classesObject



20
21
22
# File 'lib/configure_me/nesting.rb', line 20

def nested_classes
  @nested_classes ||= {}
end

#parent_config_klassObject



24
25
26
# File 'lib/configure_me/nesting.rb', line 24

def parent_config_klass
  @parent_config_klass ||= nil
end

#parent_config_klass=(parent_config_klass) ⇒ Object



28
29
30
# File 'lib/configure_me/nesting.rb', line 28

def parent_config_klass=(parent_config_klass)
  @parent_config_klass = parent_config_klass
end