Class: Credman::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/credman/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#settings_listObject



20
21
22
# File 'lib/credman/configuration.rb', line 20

def settings_list
  @settings_list ||= []
end

Class Method Details

.add_setting(name, default_value = nil) ⇒ Object



9
10
11
12
13
# File 'lib/credman/configuration.rb', line 9

def self.add_setting(name, default_value = nil)
  attr_accessor name
  instance.send("#{name}=", default_value)
  instance.settings_list = instance.settings_list.push(name.to_sym)
end

.resetObject



15
16
17
18
# File 'lib/credman/configuration.rb', line 15

def self.reset
  load __FILE__
  self
end

Instance Method Details

#load_from_yml(config_path = "config/credman.yml") ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/credman/configuration.rb', line 28

def load_from_yml(config_path = "config/credman.yml")
  return unless File.exist?(config_path)

  settings = YAML.load_file(config_path)
  return unless settings

  settings.each do |setting_name, setting_value|
    send("#{setting_name}=", setting_value) if setting_exists?(setting_name.to_sym)
  end
end

#setting_exists?(setting_name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/credman/configuration.rb', line 24

def setting_exists?(setting_name)
  settings_list.include?(setting_name)
end