Class: Ghaki::Env::Engine

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ghaki/env/engine.rb

Overview

Run time environment discovery singleton.

  • Detects GHAKI_RUN_ENV, RAILS_ENV, RACK_ENV in environment.

  • Detects the RAILS_ENV global constant.

  • Detects Sinatra and Merb classes in the Ruby namespace.

Examples

Ghaki::Env.instance.clear_environment
RACK_ENV = 'testing'
Ghaki::Env.instance.environment        #=> 'testing'

Instance Method Summary collapse

Instance Method Details

#assert_environmentObject

Throw an exception if the environment is not valid.



41
42
43
# File 'lib/ghaki/env/engine.rb', line 41

def assert_environment
  _assert_environment( @environment )
end

#clear_environmentObject

Clears current set environment.



35
36
37
# File 'lib/ghaki/env/engine.rb', line 35

def clear_environment
  @environment = nil
end

#detect_environmentObject

Check environment for current run state.



47
48
49
# File 'lib/ghaki/env/engine.rb', line 47

def detect_environment
  _assert_environment( self._detect_environment )
end

#environmentObject

Environment read attribute, detects current environment if not already set.



23
24
25
# File 'lib/ghaki/env/engine.rb', line 23

def environment
  @environment ||= self.detect_environment
end

#environment=(val) ⇒ Object

Environment write attribute. Asserts on acceptable values.



29
30
31
# File 'lib/ghaki/env/engine.rb', line 29

def environment= val
  @environment = _assert_environment( val )
end