Class: Environment

Inherits:
Object show all
Defined in:
lib/madvertise/ext/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 = nil) ⇒ Environment

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

Parameters:

  • key (String) (defaults to: nil)

    The key in ENV to contain the current program environment.



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

def initialize(key=nil)
  @key = key
end

Instance Attribute Details

#keyObject

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.

Returns:

  • (Boolean)


38
39
40
# File 'lib/madvertise/ext/environment.rb', line 38

def dev?
  to_sym == :development
end

#modeString

Retreive the current environment mode.

Returns:

  • (String)

    The current environment mode.



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

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

#prod?Boolean

Return true if the current environment is production.

Returns:

  • (Boolean)


33
34
35
# File 'lib/madvertise/ext/environment.rb', line 33

def prod?
  to_sym == :production
end

#set(value) ⇒ Object

Set the environment mode.

Parameters:

  • The (String)

    new environment mode.



50
51
52
# File 'lib/madvertise/ext/environment.rb', line 50

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

#test?Boolean

Return true if the current environment is test.

Returns:

  • (Boolean)


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

def test?
  to_sym == :test
end

#to_symSymbol

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

Returns:

  • (Symbol)

    The current environment mode.



28
29
30
# File 'lib/madvertise/ext/environment.rb', line 28

def to_sym
  mode.to_sym
end