Class: Environment
Overview
A simple convenience class to support multiple environments in which a program can run (e.g. development, production, etc).
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#dev? ⇒ Boolean
Return true if the current environment is
development
. -
#initialize(key = nil) ⇒ Environment
constructor
Create a new Environment instance with the corresponding
key
in theENV
hash. -
#mode ⇒ String
Retreive the current environment mode.
-
#prod? ⇒ Boolean
Return true if the current environment is
production
. -
#set(value) ⇒ Object
Set the environment mode.
-
#test? ⇒ Boolean
Return true if the current environment is
test
. -
#to_sym ⇒ Symbol
Retrieve the current environment mode and convert it to a symbol.
Constructor Details
#initialize(key = nil) ⇒ Environment
Create a new Environment instance with the corresponding key
in the ENV
hash.
14 15 16 |
# File 'lib/madvertise/ext/environment.rb', line 14 def initialize(key=nil) @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/madvertise/ext/environment.rb', line 6 def key @key end |
Instance Method Details
#dev? ⇒ Boolean
Return true if the current environment is development
.
40 41 42 |
# File 'lib/madvertise/ext/environment.rb', line 40 def dev? to_sym == :development end |
#mode ⇒ String
Retreive the current environment mode.
21 22 23 24 25 |
# File 'lib/madvertise/ext/environment.rb', line 21 def mode ENV[@key] || 'development' rescue 'development' end |
#prod? ⇒ Boolean
Return true if the current environment is production
.
35 36 37 |
# File 'lib/madvertise/ext/environment.rb', line 35 def prod? to_sym == :production end |
#set(value) ⇒ Object
Set the environment mode.
52 53 54 |
# File 'lib/madvertise/ext/environment.rb', line 52 def set(value) ENV[@key] = value.to_s end |
#test? ⇒ Boolean
Return true if the current environment is test
.
45 46 47 |
# File 'lib/madvertise/ext/environment.rb', line 45 def test? to_sym == :test end |
#to_sym ⇒ Symbol
Retrieve the current environment mode and convert it to a symbol.
30 31 32 |
# File 'lib/madvertise/ext/environment.rb', line 30 def to_sym mode.to_sym end |