Class: Petra::Configuration::Configurator
- Inherits:
-
Object
- Object
- Petra::Configuration::Configurator
- Defined in:
- lib/petra/configuration/configurator.rb
Direct Known Subclasses
Class Method Summary collapse
-
.base_config(name, accept_value: true) ⇒ Object
Generates a very basic configuration method which accepts a block or input value (see
options
).
Instance Method Summary collapse
-
#__persist! ⇒ Object
Persists the new configuration values in the global configuration, meaning that it merges its options into the specific configuration hash under a certain key.
-
#initialize ⇒ Configurator
constructor
A new instance of Configurator.
Constructor Details
#initialize ⇒ Configurator
Returns a new instance of Configurator.
38 39 40 |
# File 'lib/petra/configuration/configurator.rb', line 38 def initialize @options = Petra.configuration.__configuration_hash(*__namespaces).deep_dup end |
Class Method Details
.base_config(name, accept_value: true) ⇒ Object
Generates a very basic configuration method which accepts a block or input value (see options
)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/petra/configuration/configurator.rb', line 19 def self.base_config(name, accept_value: true) if accept_value define_method name do |value = nil, &proc| if proc __configuration[name.to_sym] = proc elsif !value.nil? __configuration[name.to_sym] = value else fail ArgumentError, 'Either a value or a configuration block have to be given.' end end else define_method name do |&proc| fail(ArgumentError, 'A configuration block has to be given.') unless proc __configuration[name.to_sym] = proc end end end |
Instance Method Details
#__persist! ⇒ Object
Persists the new configuration values in the global configuration, meaning that it merges its options into the specific configuration hash under a certain key
47 48 49 |
# File 'lib/petra/configuration/configurator.rb', line 47 def __persist! Petra.configuration.__configuration_hash(*__namespaces).deep_merge!(__configuration) end |