Class: AIPP::Environment

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/aipp/environment.rb

Overview

Runtime environment

Runtime environment objects inherit from OpenStruct but feature some extensions:

  • Use replace to replace the current key/value table with the given hash.

  • Use merge to merge the given hash into the current key/value hash.

  • When reading a value using square brackets, the key is implicitly converted to Symbol.

Examples:

AIPP.config                      # => AIPP::Environment::Config
AIPP.config.foo                  # => nil
AIPP.config.foo = :bar           # => :bar
AIPP.config.replace(fii: :bir)
AIPP.config.foo                  # => nil
AIPP.config.fii                  # => :bir
AIPP.config.read!                # method defined on Config class

Defined Under Namespace

Classes: Borders, Cache, Config, Fixtures, Options

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



75
76
77
78
79
80
81
82
83
# File 'lib/aipp/environment.rb', line 75

def initialize
  [Cache, Borders, Fixtures, Options, Config].each do |klass|
    attribute = klass.to_s.split('::').last.downcase
    instance_variable_set("@#{attribute}", klass.new)
    AIPP.define_singleton_method(attribute) do
      Environment.instance.instance_variable_get "@#{attribute}"
    end
  end
end