Class: Rage::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/env.rb

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.



6
7
8
9
10
11
12
13
# File 'lib/rage/env.rb', line 6

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



15
16
17
# File 'lib/rage/env.rb', line 15

def method_missing(method_name, *, &)
  method_name.end_with?("?") ? false : super
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  @env == other
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rage/env.rb', line 19

def respond_to_missing?(method_name, include_private = false)
  method_name.end_with?("?")
end

#to_sObject



31
32
33
# File 'lib/rage/env.rb', line 31

def to_s
  @env
end

#to_symObject



27
28
29
# File 'lib/rage/env.rb', line 27

def to_sym
  @env.to_sym
end