Class: DiceBag::Configuration

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



8
9
10
# File 'lib/dice_bag/configuration.rb', line 8

def initialize
  @prefixed = Hash.new
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