Class AppConfig::Base
In: lib/app_config/base.rb
Parent: Object

The Base storage class. Acts as a wrapper for the different storage methods.

See each storage method‘s documentation for their specific options.

Valid storage methods:

TODO: Purge AppConfig options (ie, those not related to the user-end).

Methods

[]   []=   empty?   env   environment   new   storage   to_hash  

Constants

DEFAULTS = { :storage_method => :memory, }   TODO: All these DEFAULTS constants are kinda annoying.

Public Class methods

Accepts either a hash of options or a block (which overrides any options passed in the hash).

[Source]

# File lib/app_config/base.rb, line 26
    def initialize(options = {}, &block)
      @options = DEFAULTS.merge(options)
      yield @options if block_given?

      determine_storage_method if @options[:uri]
      @storage_method = initialize_storage_method
      @storage = @storage_method.data
    end

Public Instance methods

Access the key‘s value in storage.

[Source]

# File lib/app_config/base.rb, line 36
    def [](key)
      if storage.respond_to?(:[])
        storage[key]
      else
        raise AppConfig::Error::MustOverride.new('#[]')
      end
    end

[Source]

# File lib/app_config/base.rb, line 44
    def []=(key, value)
      if storage.respond_to?(:[]=)
        storage[key] = value
      else
        raise AppConfig::Error::MustOverride.new('#[]=')
      end
    end

[Source]

# File lib/app_config/base.rb, line 52
    def empty?
      if storage.respond_to?(:empty?)
        storage.empty?
      else
        raise AppConfig::Error::MustOverride.new('#empty?')
      end
    end
env()

Alias for environment

[Source]

# File lib/app_config/base.rb, line 60
    def environment
      (@options[:environment] || @options[:env]) || nil
    end

Returns the @storage contents, which is what is exposed as the configuration.

[Source]

# File lib/app_config/base.rb, line 67
    def storage
      environment ? @storage[environment] : @storage
    end

[Source]

# File lib/app_config/base.rb, line 71
    def to_hash
      storage.to_hash
    end

[Validate]