Module: Configuration::InstanceMethods

Includes:
Enumerable
Defined in:
lib/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



72
73
74
75
# File 'lib/configuration.rb', line 72

def method_missing m, *a, &b
  return(Pure[@__parent].send m, *a, &b) rescue super if @__parent
  super
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



64
65
66
# File 'lib/configuration.rb', line 64

def name
  @name
end

Instance Method Details

#dupObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/configuration.rb', line 94

def dup
  ret = self.class.new @name
  each do |name|
    val = __send__ name.to_sym
    if Configuration === val
      val = val.dup
      val.instance_variable_set('@__parent', ret)
      DSL.evaluate(ret, name.to_sym => val)
    else
      DSL.evaluate(ret, name.to_sym => (val.dup rescue val))
    end
  end
  ret
end

#eachObject



79
80
81
# File 'lib/configuration.rb', line 79

def each
  methods(false).each{|v| yield v }
end

#initialize(*argv, &block) ⇒ Object



66
67
68
69
70
# File 'lib/configuration.rb', line 66

def initialize *argv, &block
  options = Hash === argv.last ? argv.pop : Hash.new
  @name = argv.shift
  DSL.evaluate(self, options, &block)
end

#to_hashObject



83
84
85
86
87
88
# File 'lib/configuration.rb', line 83

def to_hash
  inject({}){ |h,name|
    val = __send__(name.to_sym)
    h.update name.to_sym => Configuration === val ? val.to_hash : val
  }
end

#update(options = {}, &block) ⇒ Object



90
91
92
# File 'lib/configuration.rb', line 90

def update options = {}, &block
  DSL.evaluate(self, options, &block)
end