Class: Knowledge::Setters::Knowledge

Inherits:
Base
  • Object
show all
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

Knowledge::Setter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKnowledge

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

#configurationKnowledge::Configuration (readonly)

Returns the current value of configuration.

Returns:



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

Parameters:

  • :name (String | Symbol)
  • :value (Any)


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