Class: Rage::Env
- Inherits:
-
Object
show all
- Defined in:
- lib/rage/env.rb
Overview
Rage::Env represents the current environment of the Rage application.
The class automatically detects the application’s current environment by checking the RAGE_ENV, RAILS_ENV, and RACK_ENV environment variables. It provides predicate methods to check which environment is active.
Constant Summary
collapse
- STANDARD_ENVS =
%w(development test staging production)
Instance Method Summary
collapse
Constructor Details
#initialize(env) ⇒ Env
Returns a new instance of Env.
17
18
19
20
21
22
23
24
|
# File 'lib/rage/env.rb', line 17
def initialize(env)
@env = env
STANDARD_ENVS.each do |standard_env|
self.class.define_method("#{standard_env}?") { false } if standard_env != @env
end
self.class.define_method("#{@env}?") { true }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
26
27
28
|
# File 'lib/rage/env.rb', line 26
def method_missing(method_name, *, &)
method_name.end_with?("?") ? false : super
end
|
Instance Method Details
#==(other) ⇒ Object
34
35
36
|
# File 'lib/rage/env.rb', line 34
def ==(other)
@env == other
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/rage/env.rb', line 30
def respond_to_missing?(method_name, include_private = false)
method_name.end_with?("?")
end
|
#to_s ⇒ Object
46
47
48
|
# File 'lib/rage/env.rb', line 46
def to_s
@env
end
|
#to_str ⇒ Object
42
43
44
|
# File 'lib/rage/env.rb', line 42
def to_str
@env
end
|
#to_sym ⇒ Object
38
39
40
|
# File 'lib/rage/env.rb', line 38
def to_sym
@env.to_sym
end
|