Class: Perennial::Settings
Constant Summary collapse
- @@verbose =
false- @@log_level =
:info- @@daemon =
false
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .daemon? ⇒ Boolean
- .default_settings_path ⇒ Object
- .default_settings_path=(value) ⇒ Object
- .library_root ⇒ Object
- .library_root=(path) ⇒ Object
- .root ⇒ Object
- .root=(path) ⇒ Object
- .setup(options = {}) ⇒ Object
- .setup!(options = {}) ⇒ Object
- .setup? ⇒ Boolean
- .to_hash ⇒ Object
- .verbose? ⇒ Boolean
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
14 15 16 |
# File 'lib/perennial/settings.rb', line 14 def daemon? !!@@daemon end |
.default_settings_path ⇒ Object
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_root ⇒ Object
34 35 36 |
# File 'lib/perennial/settings.rb', line 34 def library_root @@library_root ||= File.(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.(path.to_str) end |
.root ⇒ Object
26 27 28 |
# File 'lib/perennial/settings.rb', line 26 def root @@root ||= File.(File.dirname(__FILE__) / ".." / "..") end |
.root=(path) ⇒ Object
22 23 24 |
# File 'lib/perennial/settings.rb', line 22 def root=(path) @@root = File.(path.to_str) end |
.setup(options = {}) ⇒ Object
51 52 53 |
# File 'lib/perennial/settings.rb', line 51 def setup( = {}) self.setup!() 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!( = {}) @@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! @@configuration.symbolize_keys! # Generate a module mod = generate_settings_accessor_mixin extend mod include mod @@setup = true end |
.setup? ⇒ Boolean
38 39 40 |
# File 'lib/perennial/settings.rb', line 38 def setup? @@setup ||= false end |
.to_hash ⇒ Object
82 83 84 |
# File 'lib/perennial/settings.rb', line 82 def to_hash self.configuration.dup end |
.verbose? ⇒ Boolean
18 19 20 |
# File 'lib/perennial/settings.rb', line 18 def verbose? !!@@verbose end |