Class: SettingsJs::Backends::SettingsLogic
- Inherits:
-
Object
- Object
- SettingsJs::Backends::SettingsLogic
- Defined in:
- lib/settings_js/backends/settings_logic.rb
Overview
Public: SettingsLogic backend implementation to get values of Settings from string.
klass - Class which is SettingsLogic in the application.
Examples
settingsjs_backend = Settings::Backends::SettingsLogic.new(MySettings)
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(klass) ⇒ SettingsLogic
constructor
A new instance of SettingsLogic.
-
#to_hash(base_key) ⇒ Object
Public: Use application Settingslogic class to get values of a key.
Constructor Details
#initialize(klass) ⇒ SettingsLogic
Returns a new instance of SettingsLogic.
16 17 18 |
# File 'lib/settings_js/backends/settings_logic.rb', line 16 def initialize(klass) self.klass = klass end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
14 15 16 |
# File 'lib/settings_js/backends/settings_logic.rb', line 14 def klass @klass end |
Instance Method Details
#to_hash(base_key) ⇒ Object
Public: Use application Settingslogic class to get values of a key.
base_key - String with path keys seperated by dots.
Examples
Settingsjs::Backends::SettingsLogic.new(MySettings).to_hash('key1.subkey1_1')
# => { subkey1_1: 'Awesome value!' }
Returns the Hash value.
30 31 32 33 34 35 36 37 38 |
# File 'lib/settings_js/backends/settings_logic.rb', line 30 def to_hash(base_key) keys = base_key.split(/\./) hash_key = keys.last base_hash = klass.send(keys.shift) keys.each { |key| base_hash = base_hash.send(key) } { hash_key => base_hash } end |