Sha256: 3c2eccb2726d416e866bffc100c5f7b0a91d047ce366ca00ae82a523d949b6bb

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

class Shakapacker::Env
  delegate :config_path, :logger, to: :@instance

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

  def initialize(instance)
    @instance = instance
  end

  def inquire
    fallback_env_warning if config_path.exist? && !current
    current || Shakapacker::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/shakapacker.yml, falling back to #{Shakapacker::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

14 entries across 14 versions & 1 rubygems

Version Path
shakapacker-7.2.3 lib/shakapacker/env.rb
shakapacker-7.3.0.beta.1 lib/shakapacker/env.rb
shakapacker-7.2.2 lib/shakapacker/env.rb
shakapacker-7.2.1 lib/shakapacker/env.rb
shakapacker-7.2.0 lib/shakapacker/env.rb
shakapacker-7.2.0.rc.0 lib/shakapacker/env.rb
shakapacker-7.1.0 lib/shakapacker/env.rb
shakapacker-7.0.3 lib/shakapacker/env.rb
shakapacker-7.0.2 lib/shakapacker/env.rb
shakapacker-7.0.1 lib/shakapacker/env.rb
shakapacker-7.0.0 lib/shakapacker/env.rb
shakapacker-7.0.0.rc.2 lib/shakapacker/env.rb
shakapacker-7.0.0.rc.1 lib/shakapacker/env.rb
shakapacker-7.0.0.rc.0 lib/shakapacker/env.rb