Sha256: 9386a5a192bb0deb156c1014fabadae0925bf830384dc8748a749bce348adf79

Contents?: true

Size: 1000 Bytes

Versions: 22

Compression:

Stored size: 1000 Bytes

Contents

class Webpacker::Env
  DEFAULT = "production".freeze

  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 || DEFAULT.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 #{DEFAULT} environment"
    end

    def available_environments
      if config_path.exist?
        YAML.load(config_path.read).keys
      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

22 entries across 22 versions & 1 rubygems

Version Path
webpacker-5.3.0 lib/webpacker/env.rb
webpacker-5.2.2 lib/webpacker/env.rb
webpacker-6.0.0.beta.7 lib/webpacker/env.rb
webpacker-6.0.0.beta.6 lib/webpacker/env.rb
webpacker-6.0.0.beta.5 lib/webpacker/env.rb
webpacker-6.0.0.beta.4 lib/webpacker/env.rb
webpacker-6.0.0.beta.3 lib/webpacker/env.rb
webpacker-6.0.0.beta.2 lib/webpacker/env.rb
webpacker-6.0.0.beta.1 lib/webpacker/env.rb
webpacker-6.0.0.beta lib/webpacker/env.rb
webpacker-6.0.0.pre.2 lib/webpacker/env.rb
webpacker-6.0.0.pre.1 lib/webpacker/env.rb
webpacker-5.2.1 lib/webpacker/env.rb
webpacker-4.3.0 lib/webpacker/env.rb
webpacker-5.2.0 lib/webpacker/env.rb
webpacker-5.1.1 lib/webpacker/env.rb
webpacker-5.1.0 lib/webpacker/env.rb
webpacker-5.0.1 lib/webpacker/env.rb
webpacker-5.0.0 lib/webpacker/env.rb
webpacker-4.2.2 lib/webpacker/env.rb