Class: DiceBag::Configuration
- Inherits:
-
Object
- Object
- DiceBag::Configuration
- Defined in:
- lib/dice_bag/configuration.rb
Overview
This class abstracts access to configuration values, to be used within ERB templates. Currently, the values are read from the environment, as per the Twelve-Factor App principles.
Defined Under Namespace
Classes: PrefixedWithFallback
Instance Method Summary collapse
-
#[](prefix) ⇒ Object
Returns a Configuration::PrefixedWithFallback using the given
prefix
. -
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #method_missing(name) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 |
# File 'lib/dice_bag/configuration.rb', line 8 def initialize @prefixed = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/dice_bag/configuration.rb', line 18 def method_missing(name) if name.to_s.end_with?("!") ensured_in_production(name) else ENV[name.to_s.upcase] end end |
Instance Method Details
#[](prefix) ⇒ Object
Returns a Configuration::PrefixedWithFallback using the given prefix
.
14 15 16 |
# File 'lib/dice_bag/configuration.rb', line 14 def [](prefix) @prefixed[prefix] ||= PrefixedWithFallback.new(prefix, self) end |