<commit_before>require 'rails'

module Headshot
  module Generators
    class ConfigGenerator < ::Rails::Generators::Base
      desc "This generator configures the application so it would be able to communicate with the Headshot Flash binary."
      source_root File.expand_path('../../../../../lib/assets', __FILE__)

      def copy_flash_middleware
        say_status('copying', 'Copying Flash session cookie middleware ...')
        begin
          say_status('creating', 'Creating directory app/middlewares.')
          Dir.mkdir('app/middlewares')
        rescue Errno::EEXIST => e
          say('Directory app/middlewares exists!')
        end

        copy_file('../middlewares/flash_session_cookie_middleware.rb', 'app/middlewares/flash_session_cookie_middleware.rb')
      end

      def load_middlewares_in_application_rb
        application_rb_path = "config/application.rb"
        code_marker = "class Application < Rails::Application"
        loading_code = 'config.autoload_paths += %W(#{config.root}/app/middlewares)'
        say_status('checking', 'Checking if application.rb contains the loading code for the middleware.')
        application_rb = IO.readlines(application_rb_path)
        application_rb_lines = application_rb.join('')

        unless application_rb_lines.include?(loading_code)
          inject_into_file application_rb_path, :after => "#{code_marker}\n" do
            "\t\t#{loading_code}\n"
          end
        end
      end
    end
  end
end<commit_msg>Removed extra code for checking loader. Thor already does it.<commit_after>require 'rails'

module Headshot
  module Generators
    class ConfigGenerator < ::Rails::Generators::Base
      desc "This generator configures the application so it would be able to communicate with the Headshot Flash binary."
      source_root File.expand_path('../../../../../lib/assets', __FILE__)

      def copy_flash_middleware
        say_status('copying', 'Copying Flash session cookie middleware ...')
        begin
          say_status('creating', 'Creating directory app/middlewares.')
          Dir.mkdir('app/middlewares')
        rescue Errno::EEXIST => e
          say('Directory app/middlewares exists!')
        end

        copy_file('../middlewares/flash_session_cookie_middleware.rb', 'app/middlewares/flash_session_cookie_middleware.rb')
      end

      def load_middlewares_in_application_rb
        application_rb_path = "config/application.rb"
        code_marker = "class Application < Rails::Application"
        loading_code = 'config.autoload_paths += %W(#{config.root}/app/middlewares)'
        say_status('checking', 'Checking if application.rb contains the loading code for the middleware.')

        inject_into_file application_rb_path, :after => "#{code_marker}\n" do
          "\t\t#{loading_code}\n"
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1038961038961039, 'fraction_numerical': 0.0, 'mean_word_length': 3.036827195467422, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2135211', 'n_tokens_mistral': 804, 'n_tokens_neox': 790, 'n_words': 189}