Module: Proxy::Dynflow::SettingsLoader
- Defined in:
- lib/smart_proxy_dynflow/settings_loader.rb
Class Method Summary collapse
- .name_to_settings ⇒ Object
- .register_settings(names, object) ⇒ Object
- .settings_keys ⇒ Object
- .settings_registered?(name) ⇒ Boolean
- .settings_registry ⇒ Object
- .setup_settings(name, settings) ⇒ Object
Instance Method Summary collapse
- #initialize_settings(settings = {}) ⇒ Object
- #register_settings(names, defaults = {}) ⇒ Object
- #settings ⇒ Object
- #validate_settings! ⇒ Object
Class Method Details
.name_to_settings ⇒ Object
9 10 11 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 9 def self.name_to_settings @name_to_settings ||= {} end |
.register_settings(names, object) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 21 def self.register_settings(names, object) names = [names] unless names.is_a? Array names.each do |name| raise 'settings name has to be a symbol' unless name.is_a? Symbol raise "settings #{name} already registered" if SettingsLoader.settings_registered?(name) name_to_settings[name] = object end settings_registry[names] = object end |
.settings_keys ⇒ Object
13 14 15 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 13 def self.settings_keys @settings_keys ||= [] end |
.settings_registered?(name) ⇒ Boolean
17 18 19 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 17 def self.settings_registered?(name) name_to_settings.key?(name) end |
.settings_registry ⇒ Object
5 6 7 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 5 def self.settings_registry @settings_registry ||= {} end |
.setup_settings(name, settings) ⇒ Object
32 33 34 35 36 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 32 def self.setup_settings(name, settings) raise "Settings for #{name} were not registered" unless settings_registered?(name) name_to_settings[name].initialize_settings(settings) end |
Instance Method Details
#initialize_settings(settings = {}) ⇒ Object
43 44 45 46 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 43 def initialize_settings(settings = {}) @settings = @defaults.merge(settings) validate_settings! end |
#register_settings(names, defaults = {}) ⇒ Object
38 39 40 41 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 38 def register_settings(names, defaults = {}) SettingsLoader.register_settings(names, self) @defaults = defaults end |
#settings ⇒ Object
48 49 50 51 52 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 48 def settings raise "Settings for #{self} not initalized" unless @settings @settings end |
#validate_settings! ⇒ Object
54 55 56 |
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 54 def validate_settings! raise 'Only symbols expected in keys' unless @settings.keys.all? { |key| key.is_a? Symbol } end |