Class: LazyAnt::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_ant/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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, options|
    instance_variable_set(var, options[: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, options = {})
  writer, reader, var, question = accessor_methods(name)
  keys[var] = options

  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

.keysObject



23
24
25
# File 'lib/lazy_ant/config.rb', line 23

def self.keys
  @keys ||= {}
end