<commit_before># frozen_string_literal: true

require "rails/generators/base"
require "securerandom"

module Decidim
  module Generators
    # Installs `decidim` to a Rails app by adding the needed lines of code
    # automatically to important files in the Rails app.
    #
    # Remember that, for how generators work, actions are executed based on the
    # definition order of the public methods.
    class InstallGenerator < Rails::Generators::Base
      desc "Install decidim"
      source_root File.expand_path("templates", __dir__)

      class_option :app_name, type: :string, default: nil,
                              desc: "The name of the app"
      class_option :recreate_db, type: :boolean, default: false,
                                 desc: "Recreate db after installing decidim"

      def bundle_install
        run "bundle install"
      end

      def install
        route "mount Decidim::Core::Engine => '/'"
      end

      def copy_migrations
        rails_command "railties:install:migrations"
        recreate_db if options[:recreate_db]
      end

      def add_seeds
        append_file("db/seeds.rb", <<~SEEDS_CONTENT)
          # You can remove the 'faker' gem if you don't want Decidim seeds.
          Decidim.seed!<commit_msg>Cleanup bundler env before `bundle install` (#1873)<commit_after># frozen_string_literal: true

require "rails/generators/base"
require "securerandom"

module Decidim
  module Generators
    # Installs `decidim` to a Rails app by adding the needed lines of code
    # automatically to important files in the Rails app.
    #
    # Remember that, for how generators work, actions are executed based on the
    # definition order of the public methods.
    class InstallGenerator < Rails::Generators::Base
      desc "Install decidim"
      source_root File.expand_path("templates", __dir__)

      class_option :app_name, type: :string, default: nil,
                              desc: "The name of the app"
      class_option :recreate_db, type: :boolean, default: false,
                                 desc: "Recreate db after installing decidim"

      def bundle_install
        Bundler.with_clean_env { run "bundle install" }
      end

      def install
        route "mount Decidim::Core::Engine => '/'"
      end

      def copy_migrations
        rails_command "railties:install:migrations"
        recreate_db if options[:recreate_db]
      end

      def add_seeds
        append_file("db/seeds.rb", <<~SEEDS_CONTENT)
          # You can remove the 'faker' gem if you don't want Decidim seeds.
          Decidim.seed!
{'fraction_non_alphanumeric': 0.07398843930635839, 'fraction_numerical': 0.0015414258188824663, 'mean_word_length': 2.5512995896032833, 'pattern_counts': {'":': 0, '<': 9, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1679804', 'n_tokens_mistral': 745, 'n_tokens_neox': 717, 'n_words': 246}