Class: Knowledge::Setters::Knowledge
- Defined in:
- lib/knowledge/setters/knowledge.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::Setters::Knowledge.new.set(name: :foo, value: 'bar')
Attributes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Knowledge::Configuration
readonly
The current value of configuration.
Instance Method Summary collapse
-
#initialize ⇒ Knowledge
constructor
Just sets the basic configuration object.
-
#set(name:, value:) ⇒ Object
Sets the variable by doing black magic on Knowledge::Configuration.
Constructor Details
#initialize ⇒ Knowledge
Just sets the basic configuration object.
29 30 31 |
# File 'lib/knowledge/setters/knowledge.rb', line 29 def initialize @configuration = ::Knowledge::Configuration end |
Instance Attribute Details
#configuration ⇒ Knowledge::Configuration (readonly)
Returns the current value of configuration.
23 24 25 |
# File 'lib/knowledge/setters/knowledge.rb', line 23 def configuration @configuration end |
Instance Method Details
#set(name:, value:) ⇒ Object
Sets the variable by doing black magic on Knowledge::Configuration.
Parameters
43 44 45 46 |
# File 'lib/knowledge/setters/knowledge.rb', line 43 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 |