Class: Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/madvertise/environment.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = "RACK_ENV") ⇒ Environment

Create a new Environment instance with the corresponding key in the ENV hash.



14
15
16
# File 'lib/madvertise/environment.rb', line 14

def initialize(key = "RACK_ENV")
  @key = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/madvertise/environment.rb', line 6

def key
  @key
end

Instance Method Details

#development?Boolean Also known as: dev?

Return true if the current environment is development.



47
48
49
# File 'lib/madvertise/environment.rb', line 47

def development?
  to_sym == :development
end

#modeString

Retreive the current environment mode.



21
22
23
24
25
# File 'lib/madvertise/environment.rb', line 21

def mode
  ENV[@key] || 'development'
rescue
  'development'
end

#production?Boolean Also known as: prod?

Return true if the current environment is production.



35
36
37
# File 'lib/madvertise/environment.rb', line 35

def production?
  to_sym == :production
end

#set(value) ⇒ Object

Set the environment mode.



61
62
63
# File 'lib/madvertise/environment.rb', line 61

def set(value)
  ENV[@key] = value.to_s
end

#staging?Boolean

Return true if the current environment is production.



42
43
44
# File 'lib/madvertise/environment.rb', line 42

def staging?
  to_sym == :staging
end

#test?Boolean

Return true if the current environment is test.



54
55
56
# File 'lib/madvertise/environment.rb', line 54

def test?
  to_sym == :test
end

#to_symSymbol

Retrieve the current environment mode and convert it to a symbol.



30
31
32
# File 'lib/madvertise/environment.rb', line 30

def to_sym
  mode.to_sym
end