Class: Modgen::Configuration
Constant Summary collapse
- DEFAULT =
{}
Instance Method Summary collapse
- #configure(&block) ⇒ Object
-
#initialize(config, use_default = true) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(config, use_default = true) ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/modgen/configuration.rb', line 6 def initialize(config, use_default = true) if use_default config = DEFAULT.merge(config) end config.each do |key, value| eval <<-METHOD def #{key}(value = nil, &block) if block_given? @#{key}.instance_eval(&block) end if value.nil? if @#{key}.is_a?(Proc) return @#{key}.call end return @#{key} end self.#{key} = value end def #{key}=(value) @#{key} = value end METHOD self.send("#{key}=", value) end end |
Instance Method Details
#configure(&block) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/modgen/configuration.rb', line 38 def configure(&block) if block_given? yield self end self end |