Class: Knowledge::Setter
- Inherits:
-
Object
- Object
- Knowledge::Setter
- Defined in:
- lib/knowledge/setter.rb
Overview
Description
If you don’t have a defined strategy to manage config for your project, you can use Knowledge’s one. This is the custom setter.
Usage
@example:
Knowledge::Setter.new.set(name: :foo, value: 'bar')
Instance Method Summary collapse
-
#initialize ⇒ Setter
constructor
Just sets the basic configuration object.
-
#set(name:, value:) ⇒ Object
Description.
Constructor Details
#initialize ⇒ Setter
Just sets the basic configuration object.
24 25 26 |
# File 'lib/knowledge/setter.rb', line 24 def initialize @configuration = ::Knowledge::Configuration end |
Instance Method Details
#set(name:, value:) ⇒ Object
Description
Sets the variable by doing black magic on Knowledge::Configuration.
Parameters
40 41 42 43 |
# File 'lib/knowledge/setter.rb', line 40 def set(name:, value:) @configuration.singleton_class.class_eval { attr_accessor name.to_sym } unless @configuration.respond_to?(name) @configuration.instance_variable_set(:"@#{name}", value) end |