Class: DiceBag::Configuration::PrefixedWithFallback
- Inherits:
-
Object
- Object
- DiceBag::Configuration::PrefixedWithFallback
- Defined in:
- lib/dice_bag/configuration.rb
Overview
This class acts like Configuration but with a prefix applied to the environment variables used to provide values. This is useful for providing per-environment overrides to value in Rails projects. If the prefixed environment variable is not found, the class delegates to the provided fallback Configuration class, without the prefix.
Instance Method Summary collapse
-
#initialize(prefix, fallback) ⇒ PrefixedWithFallback
constructor
A new instance of PrefixedWithFallback.
- #method_missing(name) ⇒ Object
Constructor Details
#initialize(prefix, fallback) ⇒ PrefixedWithFallback
Returns a new instance of PrefixedWithFallback.
50 51 52 53 |
# File 'lib/dice_bag/configuration.rb', line 50 def initialize(prefix, fallback) @prefix = prefix.to_s.upcase @fallback = fallback end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
55 56 57 |
# File 'lib/dice_bag/configuration.rb', line 55 def method_missing(name) ENV["#{ @prefix }_#{ name.to_s.upcase }"] || @fallback.send(name) end |