<commit_before>module Lapine
  module Consumer
    class Environment
      attr_reader :config

      def initialize(config)
        @config = config
      end

      def load!
        set_environment
        load_rails
        require_from_config
      end

      def set_environment
        ENV['RAILS_ENV'] ||= 'development'
        ENV['RACK_ENV'] = ENV['RAILS_ENV']
      end

      def load_rails
        begin
          require 'rails'
          if ::Rails.application.respond_to?(:eager_load)
            require File.expand_path('config/environment.rb')
            ::Rails.application.eager_load!
          else
            require File.expand_path('config/application.rb')
            ::Rails::Application.initializer "lapine.load_rails" do
              ::Rails.application.config.eager_load = true
            end
            require File.expand_path('config/environment.rb')
          end
        rescue LoadError
        end
      end

      def require_from_config
        if config.require
          config.require.each do |file|
            require File.expand_path(file)
          end
        end
      end
    end
  end
end
<commit_msg>Do not overwrite RACK_ENV if set in environment<commit_after>module Lapine
  module Consumer
    class Environment
      attr_reader :config

      def initialize(config)
        @config = config
      end

      def load!
        set_environment
        load_rails
        require_from_config
      end

      def set_environment
        ENV['RAILS_ENV'] ||= 'development'
        ENV['RACK_ENV'] ||= ENV['RAILS_ENV']
      end

      def load_rails
        begin
          require 'rails'
          if ::Rails.application.respond_to?(:eager_load)
            require File.expand_path('config/environment.rb')
            ::Rails.application.eager_load!
          else
            require File.expand_path('config/application.rb')
            ::Rails::Application.initializer "lapine.load_rails" do
              ::Rails.application.config.eager_load = true
            end
            require File.expand_path('config/environment.rb')
          end
        rescue LoadError
        end
      end

      def require_from_config
        if config.require
          config.require.each do |file|
            require File.expand_path(file)
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07325383304940375, 'fraction_numerical': 0.0, 'mean_word_length': 1.7570422535211268, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5144857', 'n_tokens_mistral': 661, 'n_tokens_neox': 635, 'n_words': 141}