Module: ConfigurationDsl
- Defined in:
- lib/configuration_dsl.rb,
lib/configuration_dsl/dsl.rb,
lib/configuration_dsl/impl.rb
Defined Under Namespace
Classes: Dsl, Error, Impl
Constant Summary
collapse
- VERSION =
File.read(File.dirname(__FILE__)+"/../VERSION")
Instance Method Summary
collapse
Instance Method Details
#configuration ⇒ Object
47
48
49
50
|
# File 'lib/configuration_dsl.rb', line 47
def configuration
@configuration_dsl ||= Impl.new(self)
@configuration_dsl.find_configuration
end
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/configuration_dsl.rb', line 29
def configure(&block)
@configuration_dsl ||= Impl.new(self)
if block_given?
_module = @configuration_dsl.find_module
raise Error, "cannot find configuration module" unless _module
dsl = Dsl.new(Impl.dup_struct(configuration)) dsl.send(:extend, _module)
dsl.instance_eval(&block)
@configuration_dsl.configuration = dsl.configuration.freeze
end
callback = @configuration_dsl.find_callback
instance_eval(&callback) if callback
end
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/configuration_dsl.rb', line 10
def configure_with(configuration_module, &block)
@configuration_dsl ||= Impl.new(self)
@configuration_dsl.module = configuration_module
@configuration_dsl.callback = block if block_given?
@configuration_dsl.default_configuration!
@configuration_dsl.module.module_eval do
self::DEFAULTS.keys.each do |name|
next if method_defined?(name) module_eval <<-code
def #{name}(value)
configuration.#{name} = value
end
code
end
end
end
|