Module: HatiConfig::Environment
Overview
Environment module provides functionality for managing environment-specific configurations.
Class Method Summary collapse
-
.current_environment ⇒ Symbol
Gets the current environment.
-
.current_environment=(env) ⇒ Object
Sets the current environment.
-
.with_environment(env) { ... } ⇒ Object
Temporarily changes the environment for a block of code.
Instance Method Summary collapse
-
#current_environment ⇒ Symbol
Gets the current environment.
-
#development? ⇒ Boolean
Checks if the current environment is development.
-
#environment(env_name) { ... } ⇒ Object
Defines environment-specific configuration overrides.
-
#environment?(env) ⇒ Boolean
Checks if the current environment matches the given environment.
-
#production? ⇒ Boolean
Checks if the current environment is production.
-
#staging? ⇒ Boolean
Checks if the current environment is staging.
-
#test? ⇒ Boolean
Checks if the current environment is test.
Class Method Details
.current_environment ⇒ Symbol
Gets the current environment.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hati_config/environment.rb', line 33 def self.current_environment @current_environment ||= begin env = if ENV['HATI_ENV'] ENV['HATI_ENV'] elsif ENV['RACK_ENV'] ENV['RACK_ENV'] elsif ENV['RAILS_ENV'] ENV['RAILS_ENV'] else 'development' end env.to_sym end end |
.current_environment=(env) ⇒ Object
Sets the current environment.
26 27 28 |
# File 'lib/hati_config/environment.rb', line 26 def self.current_environment=(env) @current_environment = env&.to_sym end |
.with_environment(env) { ... } ⇒ Object
Temporarily changes the environment for a block of code.
63 64 65 66 67 68 69 |
# File 'lib/hati_config/environment.rb', line 63 def self.with_environment(env) original_env = current_environment self.current_environment = env yield ensure self.current_environment = original_env end |
Instance Method Details
#current_environment ⇒ Symbol
Gets the current environment.
51 52 53 |
# File 'lib/hati_config/environment.rb', line 51 def current_environment Environment.current_environment end |
#development? ⇒ Boolean
Checks if the current environment is development.
82 83 84 |
# File 'lib/hati_config/environment.rb', line 82 def development? environment?(:development) end |
#environment(env_name) { ... } ⇒ Object
Defines environment-specific configuration overrides.
15 16 17 18 19 |
# File 'lib/hati_config/environment.rb', line 15 def environment(env_name, &block) return unless current_environment == env_name instance_eval(&block) end |
#environment?(env) ⇒ Boolean
Checks if the current environment matches the given environment.
75 76 77 |
# File 'lib/hati_config/environment.rb', line 75 def environment?(env) current_environment == env.to_sym end |
#production? ⇒ Boolean
Checks if the current environment is production.
103 104 105 |
# File 'lib/hati_config/environment.rb', line 103 def production? environment?(:production) end |
#staging? ⇒ Boolean
Checks if the current environment is staging.
96 97 98 |
# File 'lib/hati_config/environment.rb', line 96 def staging? environment?(:staging) end |
#test? ⇒ Boolean
Checks if the current environment is test.
89 90 91 |
# File 'lib/hati_config/environment.rb', line 89 def test? environment?(:test) end |