Module: RailsEnv
- Defined in:
- lib/rails_env/rails_env.rb
Class Method Summary collapse
-
.is?(*env_names) ⇒ Boolean
Returns true if
Rails.env
matches any of the env names provided. -
.matches?(env_pattern) ⇒ Boolean
Returns true if Rails.env regexp matches the given pattern.
-
.method_missing(method_sym, *arguments, &block) ⇒ Object
Allows dynamic env checks.
-
.public? ⇒ Boolean
By default, returns true if Rails.env is ‘production’.
Class Method Details
.is?(*env_names) ⇒ Boolean
Returns true if Rails.env
matches any of the env names provided.
Names can be strings or symbols.
For example, RailsEnv.is?(:production,:staging)
returns true if Rails.env == 'production'
23 24 25 |
# File 'lib/rails_env/rails_env.rb', line 23 def self.is? *env_names env_names.any? {|env| Rails.env == env.to_s } end |
.matches?(env_pattern) ⇒ Boolean
Returns true if Rails.env regexp matches the given pattern. Pattern can be a:
-
string
-
symbol
-
regexp
For example, RailsEnv.matches?(:production) would be true if Rails.env was ‘production’ or ‘internal_production’
13 14 15 16 |
# File 'lib/rails_env/rails_env.rb', line 13 def self.matches? env_pattern env_pattern = env_pattern.to_s unless env_pattern.is_a?(Regexp) !Rails.env.match(env_pattern).nil? end |
.method_missing(method_sym, *arguments, &block) ⇒ Object
Allows dynamic env checks.
For example, RailsEnv.production?
returns true if Rails.env == 'production'
30 31 32 33 34 35 36 |
# File 'lib/rails_env/rails_env.rb', line 30 def self.method_missing method_sym, *arguments, &block if method_sym.to_s.match /^(.+)\?$/ $1 == Rails.env else raise NoMethodError end end |
.public? ⇒ Boolean
By default, returns true if Rails.env is ‘production’
4 5 6 |
# File 'lib/rails_env/rails_env.rb', line 4 def self.public? Rails.env == 'production' end |