Module: Hivent::Config::Options
Defined Under Namespace
Classes: UnsupportedOptionError
Instance Method Summary
collapse
Instance Method Details
#defaults ⇒ Object
10
11
12
|
# File 'lib/hivent/config/options.rb', line 10
def defaults
@defaults ||= {}
end
|
#option(name, options = {}) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/hivent/config/options.rb', line 18
def option(name, options = {})
defaults[name] = settings[name] = options[:default]
validators[name] = options[:validate] || ->(_value) { true }
class_eval <<-RUBY
def #{name}
settings[#{name.inspect}]
end
def #{name}=(value)
unless validators[#{name.inspect.to_sym}].(value)
raise UnsupportedOptionError.new("Unsupported value " + value.inspect + " for option #{name.inspect}")
end
settings[#{name.inspect}] = value
end
def #{name}?
#{name}
end
def reset_#{name}
settings[#{name.inspect}] = defaults[#{name.inspect}]
end
RUBY
end
|
#settings ⇒ Object
43
44
45
|
# File 'lib/hivent/config/options.rb', line 43
def settings
@settings ||= {}
end
|
#validators ⇒ Object
14
15
16
|
# File 'lib/hivent/config/options.rb', line 14
def validators
@validators ||= {}
end
|