Sha256: afbedeadd0f5c6422ea2f9d6d951021f24c8cf1aa70b6061f5e634b5e35b63e5

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

class Webpacker::Env
  delegate :config_path, :logger, to: :@webpacker

  def self.inquire(webpacker)
    new(webpacker).inquire
  end

  def initialize(webpacker)
    @webpacker = webpacker
  end

  def inquire
    fallback_env_warning if config_path.exist? && !current
    current || Webpacker::DEFAULT_ENV.inquiry
  end

  private
    def current
      Rails.env.presence_in(available_environments)
    end

    def fallback_env_warning
      logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/webpacker.yml, falling back to #{Webpacker::DEFAULT_ENV} environment"
    end

    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.message}"
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shakapacker-6.6.0 lib/webpacker/env.rb
shakapacker-6.5.6 lib/webpacker/env.rb
shakapacker-6.5.5 lib/webpacker/env.rb
shakapacker-6.5.4 lib/webpacker/env.rb
shakapacker-6.5.3 lib/webpacker/env.rb
shakapacker-6.5.2 lib/webpacker/env.rb
shakapacker-6.5.1 lib/webpacker/env.rb