Class: Perennial::Settings

Inherits:
Object show all
Defined in:
lib/perennial/settings.rb

Constant Summary collapse

@@verbose =
false
@@log_level =
:info
@@daemon =
false

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



71
72
73
74
# File 'lib/perennial/settings.rb', line 71

def [](key)
  self.setup
  return self.configuration[key.to_sym]
end

.[]=(key, value) ⇒ Object



76
77
78
79
80
# File 'lib/perennial/settings.rb', line 76

def []=(key, value)
  self.setup
  self.configuration[key.to_sym] = value
  return value
end

.daemon?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/perennial/settings.rb', line 14

def daemon?
  !!@@daemon
end

.default_settings_pathObject



42
43
44
# File 'lib/perennial/settings.rb', line 42

def default_settings_path
  @@default_settings_path ||= (root / "config" / "settings.yml")
end

.default_settings_path=(value) ⇒ Object



46
47
48
49
# File 'lib/perennial/settings.rb', line 46

def default_settings_path=(value)
  @@default_settings_path = value
  setup! if setup?
end

.library_rootObject



34
35
36
# File 'lib/perennial/settings.rb', line 34

def library_root
  @@library_root ||= File.expand_path(File.dirname(__FILE__) / ".." / "..")
end

.library_root=(path) ⇒ Object



30
31
32
# File 'lib/perennial/settings.rb', line 30

def library_root=(path)
  @@library_root = File.expand_path(path.to_str)
end

.rootObject



26
27
28
# File 'lib/perennial/settings.rb', line 26

def root
  @@root ||= File.expand_path(File.dirname(__FILE__) / ".." / "..")
end

.root=(path) ⇒ Object



22
23
24
# File 'lib/perennial/settings.rb', line 22

def root=(path)
  @@root = File.expand_path(path.to_str)
end

.setup(options = {}) ⇒ Object



51
52
53
# File 'lib/perennial/settings.rb', line 51

def setup(options = {})
  self.setup!(options) unless setup?
end

.setup!(options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/perennial/settings.rb', line 55

def setup!(options = {})
  @@configuration = {}
  settings_file = self.default_settings_path
  if File.exist?(settings_file)
    loaded_yaml = YAML.load(File.read(settings_file))
    @@configuration.merge!(loaded_yaml["default"] || {})
  end
  @@configuration.merge! options
  @@configuration.symbolize_keys!
  # Generate a module 
  mod = generate_settings_accessor_mixin
  extend  mod
  include mod
  @@setup = true
end

.setup?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/perennial/settings.rb', line 38

def setup?
  @@setup ||= false
end

.to_hashObject



82
83
84
# File 'lib/perennial/settings.rb', line 82

def to_hash
  self.configuration.dup
end

.verbose?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/perennial/settings.rb', line 18

def verbose?
  !!@@verbose
end