<commit_before>module Recipes
  class Configuration < Base
    def initialize(template)
      @template = template
    end

    def gems
      @template.gem 'rails', '~> 5.1.0'
      # Model
      @template.gem 'aasm'
      @template.gem 'keynote'
      @template.gem 'paranoia' if  @template.yes?('Do you want to use Soft Deletes?')
      # Searchs
      @template.gem 'ransack' if  @template.yes?('Do you want to use Ransack?')
      @template.gem 'kaminari'
      @template.gem 'searchkick' if  @template.yes?('Are you going to use ElasticSearch?')
      # Emails
      @template.gem 'premailer-rails'

      yield if block_given?

      @template.gem_group :development, :test do |group|
        group.gem 'bundler-audit', require: false
        group.gem 'byebug'
        group.gem 'rspec-rails'
        group.gem 'spring'
        group.gem 'figaro'
        group.gem 'letter_opener_web'
        group.gem 'factory_bot_rails'
        group.gem 'faker'
        group.gem 'listen'
        group.gem 'pry-rails'
        group.gem 'pry-coolline'
        group.gem 'pry-byebug'
        group.gem 'rubocop', require: false
      end

      @template.gem_group :development do |group|
        group.gem 'spring-commands-rspec', require: false
        group.gem 'better_errors'
      end

      @template.gem_group :test do |group|
        group.gem 'simplecov', require: false
        group.gem 'capybara', require: false
        group.gem 'capybara-webkit', require: false
        group.gem 'database_cleaner', require: false
        group.gem 'fakeredis', require: false
        group.gem 'poltergeist', require: false
        group.gem 'shoulda-matchers', require: false
      end
    end

    def cook
      create_application_yml
      create_routes_file
      set_error_handling
      add_rubocop
    end

    private

    def create_application_yml
      @template.create_file 'config/application.yml'
      @template.create_file 'config/application.yml.example'
    end

    def create_routes_file
      @template.remove_file 'config/routes.rb'
      @template.create_file 'config/routes.rb' do <<~RUBY
        Rails.application.routes.draw do
        end
      RUBY
      end
    end

    def set_error_handling
      @template.insert_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<~RUBY<commit_msg>Add Hound config file<commit_after>module Recipes
  class Configuration < Base
    def initialize(template)
      @template = template
    end

    def gems
      @template.gem 'rails', '~> 5.1.0'
      # Model
      @template.gem 'aasm'
      @template.gem 'keynote'
      @template.gem 'paranoia' if  @template.yes?('Do you want to use Soft Deletes?')
      # Searchs
      @template.gem 'ransack' if  @template.yes?('Do you want to use Ransack?')
      @template.gem 'kaminari'
      @template.gem 'searchkick' if  @template.yes?('Are you going to use ElasticSearch?')
      # Emails
      @template.gem 'premailer-rails'

      yield if block_given?

      @template.gem_group :development, :test do |group|
        group.gem 'bundler-audit', require: false
        group.gem 'byebug'
        group.gem 'rspec-rails'
        group.gem 'spring'
        group.gem 'figaro'
        group.gem 'letter_opener_web'
        group.gem 'factory_bot_rails'
        group.gem 'faker'
        group.gem 'listen'
        group.gem 'pry-rails'
        group.gem 'pry-coolline'
        group.gem 'pry-byebug'
        group.gem 'rubocop', require: false
      end

      @template.gem_group :development do |group|
        group.gem 'spring-commands-rspec', require: false
        group.gem 'better_errors'
      end

      @template.gem_group :test do |group|
        group.gem 'simplecov', require: false
        group.gem 'capybara', require: false
        group.gem 'capybara-webkit', require: false
        group.gem 'database_cleaner', require: false
        group.gem 'fakeredis', require: false
        group.gem 'poltergeist', require: false
        group.gem 'shoulda-matchers', require: false
      end
    end

    def cook
      create_application_yml
      create_hound_yml
      create_routes_file
      set_error_handling
      add_rubocop
    end

    private

    def create_hound_yml
      @template.create_file '.hound.yml' do <<~CODE
        ruby:
        \s\sconfig_file: .rubocop.yml
        scss:
        \s\senabled: false
      CODE
      end
    end

    def create_application_yml
      @template.create_file 'config/application.yml'
      @template.create_file 'config/application.yml.example'
    end

    def create_routes_file
      @template.remove_file 'config/routes.rb'
      @template.create_file 'config/routes.rb' do <<~RUBY
        Rails.application.routes.draw do
        end
      RUBY
      end
    end

    def set_error_handling
      @template.insert_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<~RUBY
{'fraction_non_alphanumeric': 0.10006113715100877, 'fraction_numerical': 0.0012227430201752598, 'mean_word_length': 2.343324250681199, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '3361456', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1540, 'n_words': 370}