Class: Shakapacker::Env
- Inherits:
-
Object
- Object
- Shakapacker::Env
- Defined in:
- sig/shakapacker/env.rbs,
lib/shakapacker/env.rb
Overview
Environment inquiry for Shakapacker
Constant Summary collapse
- FALLBACK_ENV =
"production".freeze
Class Method Summary collapse
-
.inquire(instance) ⇒ ActiveSupport::StringInquirer
Returns the current Rails environment as an ActiveSupport::StringInquirer.
Instance Method Summary collapse
- #available_environments ⇒ Array[String], Hash[String, untyped]
-
#config_path ⇒ Pathname
Returns the config path.
- #current ⇒ ActiveSupport::StringInquirer?
- #fallback_env_warning ⇒ void
-
#initialize(instance) ⇒ Env
constructor
Creates a new env instance.
-
#inquire ⇒ ActiveSupport::StringInquirer
Returns the environment inquiry.
-
#logger ⇒ ActiveSupport::TaggedLogging
Returns the logger.
Constructor Details
#initialize(instance) ⇒ Env
Creates a new env instance
7 8 9 |
# File 'sig/shakapacker/env.rbs', line 7 def initialize(instance) @instance = instance end |
Class Method Details
.inquire(instance) ⇒ ActiveSupport::StringInquirer
Returns the current Rails environment as an ActiveSupport::StringInquirer
4 5 6 |
# File 'sig/shakapacker/env.rbs', line 4 def self.inquire(instance) new(instance).inquire end |
Instance Method Details
#available_environments ⇒ Array[String], Hash[String, untyped]
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shakapacker/env.rb', line 42 def available_environments if config_path.exist? begin YAML.load_file(config_path.to_s, aliases: true) rescue ArgumentError YAML.load_file(config_path.to_s) end else [].freeze end rescue Psych::SyntaxError => e raise "YAML syntax error occurred while parsing #{config_path}. " \ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ "Error: #{e.}" end |
#config_path ⇒ Pathname
Returns the config path
13 |
# File 'sig/shakapacker/env.rbs', line 13
def config_path: () -> Pathname
|
#current ⇒ ActiveSupport::StringInquirer?
20 21 22 23 24 25 26 27 |
# File 'lib/shakapacker/env.rb', line 20 def current env = if defined?(Rails) && Rails.respond_to?(:env) Rails.env else ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || Shakapacker::DEFAULT_ENV end env.presence_in(available_environments) end |
#fallback_env_warning ⇒ void
This method returns an undefined value.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/shakapacker/env.rb', line 29 def fallback_env_warning env_value = if defined?(Rails) && Rails.respond_to?(:env) Rails.env else ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || Shakapacker::DEFAULT_ENV end logger.info "RAILS_ENV=#{env_value} environment is not defined in #{config_path}, falling back to #{FALLBACK_ENV} environment" rescue NameError, NoMethodError # Logger may not be fully functional without Rails (e.g., ActiveSupport::IsolatedExecutionState # is not available). Fall back to puts, matching Configuration#log_fallback. puts "RAILS_ENV=#{env_value} environment is not defined in #{config_path}, falling back to #{FALLBACK_ENV} environment" end |
#inquire ⇒ ActiveSupport::StringInquirer
Returns the environment inquiry
10 11 12 13 |
# File 'sig/shakapacker/env.rbs', line 10 def inquire fallback_env_warning if config_path.exist? && !current (current || FALLBACK_ENV).inquiry end |
#logger ⇒ ActiveSupport::TaggedLogging
Returns the logger
16 |
# File 'sig/shakapacker/env.rbs', line 16
def logger: () -> ActiveSupport::TaggedLogging
|