Class: RKit::Core::Configurer
- Inherits:
-
Object
- Object
- RKit::Core::Configurer
- Defined in:
- lib/r_kit/core/configurer.rb
Instance Attribute Summary collapse
-
#_aliases ⇒ Object
Returns the value of attribute _aliases.
-
#_base ⇒ Object
Returns the value of attribute _base.
-
#_config ⇒ Object
Returns the value of attribute _config.
-
#_presets ⇒ Object
Returns the value of attribute _presets.
Instance Method Summary collapse
- #alias(*name, old_name) ⇒ Object
- #alias_config(*name, old_name) ⇒ Object
- #config(*name, default) ⇒ Object
- #fingerprint ⇒ Object
-
#initialize(base, config = {}) ⇒ Configurer
constructor
A new instance of Configurer.
- #inspect ⇒ Object
- #load!(config) ⇒ Object
- #load_alias! ⇒ Object
- #load_config!(config_options) ⇒ Object
- #load_preset!(name) ⇒ Object
- #load_public_accessor! ⇒ Object
- #preset(name, config) ⇒ Object
Constructor Details
#initialize(base, config = {}) ⇒ Configurer
Returns a new instance of Configurer.
4 5 6 7 8 9 |
# File 'lib/r_kit/core/configurer.rb', line 4 def initialize base, config = {} @_base = base @_config = config @_presets = Hash.new{ |hash, key| hash[key] = self.class.new(_base) } @_aliases = [] end |
Instance Attribute Details
#_aliases ⇒ Object
Returns the value of attribute _aliases.
2 3 4 |
# File 'lib/r_kit/core/configurer.rb', line 2 def _aliases @_aliases end |
#_base ⇒ Object
Returns the value of attribute _base.
2 3 4 |
# File 'lib/r_kit/core/configurer.rb', line 2 def _base @_base end |
#_config ⇒ Object
Returns the value of attribute _config.
2 3 4 |
# File 'lib/r_kit/core/configurer.rb', line 2 def _config @_config end |
#_presets ⇒ Object
Returns the value of attribute _presets.
2 3 4 |
# File 'lib/r_kit/core/configurer.rb', line 2 def _presets @_presets end |
Instance Method Details
#alias(*name, old_name) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/r_kit/core/configurer.rb', line 34 def alias *name, old_name new_name = name.pop config = name.inject(_config){ |config, nested| config = config[nested] } config[new_name] = config[old_name] if config[new_name].blank? end |
#alias_config(*name, old_name) ⇒ Object
30 31 32 |
# File 'lib/r_kit/core/configurer.rb', line 30 def alias_config *name, old_name _aliases << [name, old_name] end |
#config(*name, default) ⇒ Object
21 22 23 |
# File 'lib/r_kit/core/configurer.rb', line 21 def config *name, default _config.deep_merge! [*name, default].reverse.inject{ |nested, key| Hash[key, nested] } end |
#fingerprint ⇒ Object
66 67 68 |
# File 'lib/r_kit/core/configurer.rb', line 66 def fingerprint _config.sort.join end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/r_kit/core/configurer.rb', line 62 def inspect _config.inspect end |
#load!(config) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/r_kit/core/configurer.rb', line 54 def load! config load_preset! config.delete(:preset) load_config! config load_alias! load_public_accessor! end |
#load_alias! ⇒ Object
41 42 43 44 45 |
# File 'lib/r_kit/core/configurer.rb', line 41 def load_alias! _aliases.each do |(name, old_name)| self.alias *name, old_name end end |
#load_config!(config_options) ⇒ Object
25 26 27 |
# File 'lib/r_kit/core/configurer.rb', line 25 def load_config! _config.deep_merge! end |
#load_preset!(name) ⇒ Object
16 17 18 |
# File 'lib/r_kit/core/configurer.rb', line 16 def load_preset! name _config.deep_merge! _presets[name]._config end |
#load_public_accessor! ⇒ Object
48 49 50 51 |
# File 'lib/r_kit/core/configurer.rb', line 48 def load_public_accessor! _base.const_set :CONFIG, OpenStruct.new(_config) _base.define_singleton_method("config"){ self::CONFIG } end |
#preset(name, config) ⇒ Object
12 13 14 |
# File 'lib/r_kit/core/configurer.rb', line 12 def preset name, config _presets[name] = self.class.new(_base, config) end |