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



62
63
64
65
# File 'lib/perennial/settings.rb', line 62

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

.[]=(key, value) ⇒ Object



67
68
69
70
71
# File 'lib/perennial/settings.rb', line 67

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

.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 = 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 = path.to_str
end

.setup(options = {}) ⇒ Object



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

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

.setup!(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/perennial/settings.rb', line 46

def setup!(options = {})
  @@configuration = {}
  settings_file = root / "config" / "settings.yml"
  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



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

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