Class: Tamashii::Environment
- Inherits:
-
Hash
- Object
- Hash
- Tamashii::Environment
show all
- Defined in:
- lib/tamashii/environment.rb
Constant Summary
collapse
- RUNTIME_ENV =
%w(test development production)
Instance Method Summary
collapse
Constructor Details
#initialize(env = nil, **options) ⇒ Environment
Returns a new instance of Environment.
6
7
8
9
|
# File 'lib/tamashii/environment.rb', line 6
def initialize(env = nil, **options)
self.merge!(options)
self[:env] = env.to_s unless env.nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
11
12
13
14
|
# File 'lib/tamashii/environment.rb', line 11
def method_missing(name, *args, &block)
return is_env(name[0..-2]) if RUNTIME_ENV.include?(name[0..-2])
super
end
|
Instance Method Details
#==(other) ⇒ Object
16
17
18
|
# File 'lib/tamashii/environment.rb', line 16
def ==(other)
self.to_s == other.to_s
end
|
#is_env(env) ⇒ Object
20
21
22
|
# File 'lib/tamashii/environment.rb', line 20
def is_env(env)
self.to_s == env.to_s
end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/tamashii/environment.rb', line 24
def to_s
(self[:env] || ENV['RACK_ENV'] || "development").to_s
end
|