Class: LazyAnt::Config
- Inherits:
-
Object
- Object
- LazyAnt::Config
- Defined in:
- lib/lazy_ant/config.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
3 4 5 6 7 |
# File 'lib/lazy_ant/config.rb', line 3 def initialize self.class.keys.each do |var, | instance_variable_set(var, [:default]) end end |
Class Method Details
.accessor_methods(name) ⇒ Object
27 28 29 30 31 |
# File 'lib/lazy_ant/config.rb', line 27 def self.accessor_methods(name) attr = name.to_s.gsub(/[!\?]$/, '') var = "@#{attr}".to_sym ["#{attr}=".to_sym, name.to_sym, var, name[-1] == '?'] end |
.key(name, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lazy_ant/config.rb', line 9 def self.key(name, = {}) writer, reader, var, question = accessor_methods(name) keys[var] = define_method writer do |val| fail ArgumentError unless !question || val == false || val == true instance_variable_set(var, val) end define_method reader do instance_variable_get(var) end end |
.keys ⇒ Object
23 24 25 |
# File 'lib/lazy_ant/config.rb', line 23 def self.keys @keys ||= {} end |