Class: Configify::Base
- Inherits:
-
Object
- Object
- Configify::Base
- Defined in:
- lib/configify/base.rb
Class Method Summary collapse
- .env_variable_prefix(prefix = nil) ⇒ Object
- .properties ⇒ Object
- .property(key, default: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #load_from_env(prefix: self.class.env_variable_prefix) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
3 4 5 6 7 |
# File 'lib/configify/base.rb', line 3 def initialize self.class.properties.each do |key, value| send "#{key}=", value end end |
Class Method Details
.env_variable_prefix(prefix = nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/configify/base.rb', line 19 def env_variable_prefix prefix = nil @env_variable_prefix = prefix if prefix @env_variable_prefix end |
.properties ⇒ Object
31 32 33 |
# File 'lib/configify/base.rb', line 31 def properties @properties ||= Hash.new end |
.property(key, default: nil) ⇒ Object
25 26 27 28 29 |
# File 'lib/configify/base.rb', line 25 def property key, default: nil attr_accessor key.to_sym properties[key.to_sym] = default end |
Instance Method Details
#load_from_env(prefix: self.class.env_variable_prefix) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/configify/base.rb', line 9 def load_from_env prefix: self.class.env_variable_prefix self.class.properties.each do |key, _| env_var_name = "#{prefix}_#{key.upcase}" self.send "#{key}=", ENV[env_var_name] if ENV.has_key? env_var_name end self end |