Sha256: 8ad9c4b51a5b287916542050dbafe6c430cdb9cc53e1004a491d78c8adecea79

Contents?: true

Size: 1.24 KB

Versions: 22

Compression:

Stored size: 1.24 KB

Contents

##
# A simple convenience class to support multiple environments in which a
# program can run (e.g. development, production, etc).
#
class Environment
  attr_accessor :key

  # Create a new Environment instance with the corresponding +key+ in the +ENV+
  # hash.
  #
  # @param [String] key  The key in +ENV+ to contain the current program
  #                      environment.
  #
  def initialize(key = "RACK_ENV")
    @key = key
  end

  # Retreive the current environment mode.
  #
  # @return [String]  The current environment mode.
  def mode
    ENV[@key] || 'development'
  rescue
    'development'
  end

  # Retrieve the current environment mode and convert it to a symbol.
  #
  # @return [Symbol]  The current environment mode.
  def to_sym
    mode.to_sym
  end

  # Return true if the current environment is +production+.
  def prod?
    to_sym == :production
  end

  # Return true if the current environment is +development+.
  def dev?
    to_sym == :development
  end

  # Return true if the current environment is +test+.
  def test?
    to_sym == :test
  end

  # Set the environment mode.
  #
  # @param [String]  The new environment mode.
  def set(value)
    ENV[@key] = value.to_s
  end
end

# Global instance of {Environment}.
Env = Environment.new

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
madvertise-ext-0.9.4 lib/madvertise/environment.rb
madvertise-ext-0.9.3 lib/madvertise/environment.rb
madvertise-ext-0.9.2 lib/madvertise/environment.rb
madvertise-ext-0.9.1 lib/madvertise/environment.rb
madvertise-ext-0.9.0 lib/madvertise/environment.rb
madvertise-ext-0.8.0 lib/madvertise/environment.rb
madvertise-ext-0.7.1 lib/madvertise/environment.rb
madvertise-ext-0.7.0 lib/madvertise/environment.rb
madvertise-ext-0.6.6 lib/madvertise/environment.rb
madvertise-ext-0.6.5 lib/madvertise/environment.rb
madvertise-ext-0.6.4 lib/madvertise/environment.rb
madvertise-ext-0.6.3 lib/madvertise/environment.rb
madvertise-ext-0.6.2 lib/madvertise/environment.rb
madvertise-ext-0.6.1 lib/madvertise/environment.rb
madvertise-ext-0.6.0 lib/madvertise/environment.rb
madvertise-ext-0.5.3 lib/madvertise/environment.rb
madvertise-ext-0.5.2 lib/madvertise/environment.rb
madvertise-ext-0.5.1 lib/madvertise/environment.rb
madvertise-ext-0.5.0 lib/madvertise/environment.rb
madvertise-ext-0.4.0 lib/madvertise/ext/environment.rb