<commit_before>require 'rake'
require 'rails/generators'

module Cambium
  module Install
    class UsersGenerator < Rails::Generators::Base
      desc "Setup users model for new rails project"

      source_root File.expand_path('../../templates', __FILE__)

      # ------------------------------------------ Install Devise

      def install_devise
        unless File.exist?("#{Rails.root}/config/initializers/devise.rb")
          run_cmd "#{g} devise:install"
        end
        unless File.exist?("#{Rails.root}/app/models/user.rb")
          run_cmd "#{g} devise User"
          run_cmd "#{rake} db:migrate"
        end
      end

      # ------------------------------------------ User Model

      def add_admin_column_to_users
        file = Dir.glob("#{Rails.root}/db/migrate/*devise_create_users.rb").first
        insert_into_file(
          file, 
          "## Admin\n      t.boolean :is_admin, :default => false, \n\n      ", 
          :before => "t.timestamps"
        )
        run_cmd "#{rake} db:migrate"
      end

      def add_user_model_file
        remove_file "app/models/user.rb"
        template "app/models/user.rb", "app/models/user.rb"
        run_cmd "#{be} annotate"
      end

      # ------------------------------------------ Log In/Out Redirects

      def add_application_controller_redirects
        insert_into_file(
          "app/controllers/application_controller.rb",
          file_contents("app/controllers/application_controller.rb"),
          :after => ":exception"
        )
      end

      # ------------------------------------------ Private Methods

      private

        def run_cmd(cmd, options = {})
          print_table(
            [
              [set_color("run", :green, :bold), cmd]
            ],
            :indent => 9
          )
          if options[:quiet] == true
            `#{cmd}`
          else
            system(cmd)
          end
        end

        def template_file(name)
          File.expand_path("../../templates/#{name}", __FILE__)
        end

        def file_contents(template)
          File.read(template_file(template))
        end

        def be
          "bundle exec"
        end

        def g
          "#{be} rails g"
        end

        def rake
          "#{be} rake"
        end

        def confirm_ask(question)
          answer = ask("\n#{question}")
          match = ask("CONFIRM #{question}")
          if answer == match
            answer
          else
            say set_color("Did not match.", :red)
            confirm_ask(question)
          end
        end

    end
  end
end
<commit_msg>don't migrate until inject into migration file<commit_after>require 'rake'
require 'rails/generators'

module Cambium
  module Install
    class UsersGenerator < Rails::Generators::Base
      desc "Setup users model for new rails project"

      source_root File.expand_path('../../templates', __FILE__)

      # ------------------------------------------ Install Devise

      def install_devise
        unless File.exist?("#{Rails.root}/config/initializers/devise.rb")
          run_cmd "#{g} devise:install"
        end
        unless File.exist?("#{Rails.root}/app/models/user.rb")
          run_cmd "#{g} devise User"
        end
      end

      # ------------------------------------------ User Model

      def add_admin_column_to_users
        file = Dir.glob("#{Rails.root}/db/migrate/*devise_create_users.rb").first
        insert_into_file(
          file, 
          "## Admin\n      t.boolean :is_admin, :default => false \n\n      ", 
          :before => "t.timestamps"
        )
      end

      def add_user_model_file
        remove_file "app/models/user.rb"
        template "app/models/user.rb", "app/models/user.rb"
      end

      def migrate_and_annotate
        run_cmd "#{rake} db:migrate"
        run_cmd "#{be} annotate"
      end

      # ------------------------------------------ Log In/Out Redirects

      def add_application_controller_redirects
        insert_into_file(
          "app/controllers/application_controller.rb",
          file_contents("app/controllers/application_controller.rb"),
          :after => ":exception"
        )
      end

      # ------------------------------------------ Private Methods

      private

        def run_cmd(cmd, options = {})
          print_table(
            [
              [set_color("run", :green, :bold), cmd]
            ],
            :indent => 9
          )
          if options[:quiet] == true
            `#{cmd}`
          else
            system(cmd)
          end
        end

        def template_file(name)
          File.expand_path("../../templates/#{name}", __FILE__)
        end

        def file_contents(template)
          File.read(template_file(template))
        end

        def be
          "bundle exec"
        end

        def g
          "#{be} rails g"
        end

        def rake
          "#{be} rake"
        end

        def confirm_ask(question)
          answer = ask("\n#{question}")
          match = ask("CONFIRM #{question}")
          if answer == match
            answer
          else
            say set_color("Did not match.", :red)
            confirm_ask(question)
          end
        end

    end
  end
end

{'fraction_non_alphanumeric': 0.16549362754422675, 'fraction_numerical': 0.00038044512079132587, 'mean_word_length': 1.3642086330935252, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 11, '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': '3864316', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1423, 'n_words': 314}