Module: Proxy::Dynflow::SettingsLoader

Defined in:
lib/smart_proxy_dynflow/settings_loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.name_to_settingsObject



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_keysObject



13
14
15
# File 'lib/smart_proxy_dynflow/settings_loader.rb', line 13

def self.settings_keys
  @settings_keys ||= []
end

.settings_registered?(name) ⇒ Boolean

Returns:

  • (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_registryObject



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

#settingsObject



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