Class: RProxy::Config
- Inherits:
-
Object
- Object
- RProxy::Config
- Defined in:
- lib/r_proxy/config.rb
Class Method Summary collapse
- .add_config(name, default_value = nil) ⇒ Object
- .add_exception_config(name) ⇒ Object
- .define_set_config_value_method(name) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
59 60 61 |
# File 'lib/r_proxy/config.rb', line 59 def initialize @store = {} end |
Class Method Details
.add_config(name, default_value = nil) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/r_proxy/config.rb', line 4 def add_config(name, default_value = nil) self.define_method("#{name}") do store = instance_variable_get('@store') store["#{name}"].nil? ? default_value : store["#{name}"] end define_set_config_value_method(name) end |
.add_exception_config(name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/r_proxy/config.rb', line 13 def add_exception_config(name) self.define_method("#{name}") do store = instance_variable_get('@store') val = store["#{name}"] raise RProxy::EmptyConfigError, "#{name} cannot set as empty or nil" if val.nil? val end define_set_config_value_method(name) end |
.define_set_config_value_method(name) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/r_proxy/config.rb', line 25 def define_set_config_value_method(name) self.define_method("#{name}=") do |value| store = instance_variable_get('@store') store["#{name}"] = value end end |