Class: Konfa::Base
- Inherits:
-
Object
- Object
- Konfa::Base
- Includes:
- Deprecation, Initializer
- Defined in:
- lib/konfa.rb
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.
- .get!(variable) ⇒ Object
- .init ⇒ Object
- .init? ⇒ Boolean
- .init_with(suffix, *args) ⇒ Object
- .initialize! ⇒ Object
- .initialized? ⇒ Boolean
- .on_key_missing(key, value) ⇒ Object
- .read_from(initializer, *args) ⇒ Object
- .reinit ⇒ Object
- .true?(variable) ⇒ Boolean
- .variables ⇒ Object
- .with_config(overrides = {}) ⇒ Object
Methods included from Deprecation
Methods included from Initializer
Class Method Details
.after_initialize ⇒ Object
157 158 |
# File 'lib/konfa.rb', line 157 def after_initialize end |
.allowed_variables ⇒ Object
72 73 74 |
# File 'lib/konfa.rb', line 72 def allowed_variables {} end |
.dump ⇒ Object
106 107 108 |
# File 'lib/konfa.rb', line 106 def dump self.configuration.dup end |
.env_variable_prefix ⇒ Object
The following methods should be overridden and used to configure the configuration class
68 69 70 |
# File 'lib/konfa.rb', line 68 def env_variable_prefix 'APP_' end |
.false?(variable) ⇒ Boolean
98 99 100 |
# File 'lib/konfa.rb', line 98 def false?(variable) self.true?(variable) == false end |
.get(variable) ⇒ Object
The following methods provides the interface to this class
84 85 86 87 |
# File 'lib/konfa.rb', line 84 def get(variable) raise UnsupportedVariableError.new(variable) unless self.configuration.has_key? variable self.configuration[variable] end |
.get!(variable) ⇒ Object
89 90 91 92 |
# File 'lib/konfa.rb', line 89 def get!(variable) raise NilVariableError.new(variable) if self.get(variable).nil? self.get(variable) end |
.init ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/konfa.rb', line 115 def init deprecated "[DEPRECATION] This style of initialization will no longer be supported in Konfa 1.0 and init "\ "will be removed. Use initialize! or read_from/initialized! instead" 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
110 111 112 113 |
# File 'lib/konfa.rb', line 110 def init? deprecated "[DEPRECATION] init? will be removed in Konfa 1.0, use initialized? instead" !self.initialized && !self.initializer.nil? end |
.init_with(suffix, *args) ⇒ Object
126 127 128 129 130 |
# File 'lib/konfa.rb', line 126 def init_with(suffix, *args) deprecated "[DEPRECATION] init will be removed in Konfa 1.0. Use read_from instead" self.initializer = [:"init_with_#{suffix}", *args] self end |
.initialize! ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/konfa.rb', line 145 def initialize! raise AlreadyInitializedError if self.initialized? @initialized = true self.after_initialize self end |
.initialized? ⇒ Boolean
153 154 155 |
# File 'lib/konfa.rb', line 153 def initialized? @initialized == true end |
.on_key_missing(key, value) ⇒ Object
76 77 78 |
# File 'lib/konfa.rb', line 76 def on_key_missing(key, value) raise UnsupportedVariableError.new(key) end |
.read_from(initializer, *args) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/konfa.rb', line 137 def read_from(initializer, *args) raise AlreadyInitializedError if self.initialized? raise UnsupportedInitializerError unless self.respond_to?(:"init_with_#{initializer}") self.send(:"init_with_#{initializer}", *args) self end |
.reinit ⇒ Object
132 133 134 135 |
# File 'lib/konfa.rb', line 132 def reinit deprecated "[DEPRECATION] reinit will be removed in Konfa 1.0. Use read_from to load multiple config files" self.initialized = false end |
.true?(variable) ⇒ Boolean
94 95 96 |
# File 'lib/konfa.rb', line 94 def true?(variable) self.truthy?(self.get(variable)) end |
.variables ⇒ Object
102 103 104 |
# File 'lib/konfa.rb', line 102 def variables self.configuration.keys end |
.with_config(overrides = {}) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/konfa.rb', line 160 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 |