Class: Configuration::DSL
- Inherits:
-
Object
- Object
- Configuration::DSL
show all
- Defined in:
- lib/configuration.rb
Constant Summary
collapse
- Protected =
%r/^__|^object_id$/
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(configuration, &block) ⇒ DSL
Returns a new instance of DSL.
148
149
150
151
152
153
154
|
# File 'lib/configuration.rb', line 148
def initialize configuration, &block
@__configuration = configuration
@__singleton_class =
class << @__configuration
self
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/configuration.rb', line 161
def method_missing(m, *a, &b)
if(a.empty? and b.nil?)
return Pure[@__configuration].send(m, *a, &b)
end
if b
raise ArgumentError unless a.empty?
parent = @__configuration
name = m.to_s
configuration =
if @__configuration.respond_to?(name) and Configuration === @__configuration.send(name)
@__configuration.send name
else
Configuration.new name
end
Pure[configuration].instance_eval{ @__parent = parent }
DSL.evaluate configuration, &b
value = configuration
end
unless a.empty?
value = a.size == 1 ? a.first : a
end
@__singleton_class.module_eval do
define_method(m){ value }
end
end
|
Class Method Details
.evaluate(configuration, options = {}, &block) ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'lib/configuration.rb', line 139
def self.evaluate configuration, options = {}, &block
dsl = new configuration
options.each{|key, value| Pure[dsl].send key, value}
Pure[dsl].instance_eval(&block) if block
Pure[dsl].instance_eval{ @__configuration }
end
|
Instance Method Details
#__configuration__ ⇒ Object
156
157
158
|
# File 'lib/configuration.rb', line 156
def __configuration__
@__configuration
end
|
#Method(m) ⇒ Object
135
136
137
|
# File 'lib/configuration.rb', line 135
def Method m
@__configuration.method(m)
end
|
#Send(m, *a, &b) ⇒ Object
131
132
133
|
# File 'lib/configuration.rb', line 131
def Send(m, *a, &b)
Method(m).call(*a, &b)
end
|