Class: Konfa::Base
Class Method Summary collapse
- .after_initialize ⇒ Object
- .allowed_variables ⇒ Object
- .dump ⇒ Object
-
.env_variable_prefix ⇒ Object
The following methods should be overridden and used to configure the configuration class.
- .false?(variable) ⇒ Boolean
-
.get(variable) ⇒ Object
The following methods provides the interface to this class.
- .init ⇒ Object
- .init? ⇒ Boolean
- .init_with(suffix, *args) ⇒ Object
- .on_key_missing(key, value) ⇒ Object
- .reinit ⇒ Object
- .true?(variable) ⇒ Boolean
- .variables ⇒ Object
- .with_config(overrides = {}) ⇒ Object
Methods included from Initializer
Class Method Details
.after_initialize ⇒ Object
110 111 |
# File 'lib/konfa.rb', line 110 def after_initialize end |
.allowed_variables ⇒ Object
55 56 57 |
# File 'lib/konfa.rb', line 55 def allowed_variables {} end |
.dump ⇒ Object
84 85 86 |
# File 'lib/konfa.rb', line 84 def dump self.configuration.dup end |
.env_variable_prefix ⇒ Object
The following methods should be overridden and used to configure the configuration class
51 52 53 |
# File 'lib/konfa.rb', line 51 def env_variable_prefix 'APP_' end |
.false?(variable) ⇒ Boolean
76 77 78 |
# File 'lib/konfa.rb', line 76 def false?(variable) self.true?(variable) == false end |
.get(variable) ⇒ Object
The following methods provides the interface to this class
67 68 69 70 |
# File 'lib/konfa.rb', line 67 def get(variable) raise UnsupportedVariableError.new(variable) unless self.configuration.has_key? variable self.configuration[variable] end |
.init ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/konfa.rb', line 92 def init return unless self.init? # Set to true before calling to prevent recursion if # an initializer is accessing the configuration self.initialized = true self.send(self.initializer.first, *self.initializer[1..-1]) self.after_initialize end |
.init? ⇒ Boolean
88 89 90 |
# File 'lib/konfa.rb', line 88 def init? !self.initialized && !self.initializer.nil? end |
.init_with(suffix, *args) ⇒ Object
101 102 103 104 |
# File 'lib/konfa.rb', line 101 def init_with(suffix, *args) self.initializer = [:"init_with_#{suffix}", *args] self end |
.on_key_missing(key, value) ⇒ Object
59 60 61 |
# File 'lib/konfa.rb', line 59 def on_key_missing(key, value) raise UnsupportedVariableError.new(key) end |
.reinit ⇒ Object
106 107 108 |
# File 'lib/konfa.rb', line 106 def reinit self.initialized = false end |
.true?(variable) ⇒ Boolean
72 73 74 |
# File 'lib/konfa.rb', line 72 def true?(variable) self.truthy?(self.get(variable)) end |
.variables ⇒ Object
80 81 82 |
# File 'lib/konfa.rb', line 80 def variables self.configuration.keys end |
.with_config(overrides = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/konfa.rb', line 113 def with_config(overrides={}) original_config = dump overrides.each_pair {|k,v| self.store(k, v) } begin result = yield ensure self.configuration = original_config end result end |