Module: Jafry::Configurator
- Extended by:
- Accessor
- Defined in:
- lib/jafry/configurator.rb
Overview
Module for saving and changing scheme’s configs
Constant Summary collapse
- @@schemes_configs =
[]
Class Method Summary collapse
-
.default ⇒ Hash
Specifies default config.
-
.find_config(scheme_name) ⇒ Hash
Returns scheme by name.
-
.get_config(scheme) ⇒ Hash
Finds config by scheme name.
-
.init_or_update(scheme_name, config) ⇒ Object
Creates new or updates existed config.
-
.set_config(scheme_name, config = {}) ⇒ Object
Setups config for scheme.
Methods included from Accessor
Class Method Details
.default ⇒ Hash
Specifies default config
59 60 61 |
# File 'lib/jafry/configurator.rb', line 59 def default {id_type: Jafry.id_type, id_wrapper: Jafry.id_wrapper} end |
.find_config(scheme_name) ⇒ Hash
Returns scheme by name
51 52 53 |
# File 'lib/jafry/configurator.rb', line 51 def find_config(scheme_name) self.schemes_configs.select {|item| item[:scheme] == scheme_name}.last end |
.get_config(scheme) ⇒ Hash
Finds config by scheme name
42 43 44 |
# File 'lib/jafry/configurator.rb', line 42 def get_config(scheme) find_config(scheme)[:config] end |
.init_or_update(scheme_name, config) ⇒ Object
Creates new or updates existed config
32 33 34 35 |
# File 'lib/jafry/configurator.rb', line 32 def init_or_update(scheme_name, config) return find_config(scheme_name)[:config].merge!(config) if find_config(scheme_name) {scheme: scheme_name, config: config} end |
.set_config(scheme_name, config = {}) ⇒ Object
Setups config for scheme
20 21 22 23 24 25 |
# File 'lib/jafry/configurator.rb', line 20 def set_config(scheme_name, config={}) config = default if config.empty? scheme_config = init_or_update(scheme_name, config) self.schemes_configs << scheme_config scheme_config end |