<commit_before>require 'rails/generators/base'

module Milia
  module Generators
# *************************************************************
    
    class InstallGenerator < Rails::Generators::Base
      desc "Full installation of milia with devise"

      source_root File.expand_path("../templates", __FILE__)
  
      class_option :use_airbrake, :type => :boolean, :default => false, :desc => 'Use this option to add airbrake exception handling capabilities'
      class_option :skip_recaptcha, :type => :boolean, :default => false, :desc => 'Use this option to skip adding recaptcha for sign ups'
      class_option :skip_invite_member, :type => :boolean, :default => false, :desc => 'Use this option to skip adding invite_member capabilities'
      class_option :skip_env_email_setup, :type => :boolean, :default => false, :desc => 'Use this option to skip adding smtp email info to config/environments/*'
      class_option :org_email, :type => :string, :default => "<EMAIL>", :desc => 'define the organizational email from address'
       
# -------------------------------------------------------------
# -------------------------------------------------------------
# -------------------------------------------------------------
# -------------------------------------------------------------
  def initialize_template_variables()
    @skip_recaptcha = options.skip_recaptcha
    @skip_invite_member = options.skip_invite_member
    @use_airbrake = options.use_airbrake
  end

# -------------------------------------------------------------
# the run('bundle install') didn't work; don't know why
# -------------------------------------------------------------
      def setup_initial_stuff

        template 'initializer.rb', 'config/initializers/milia.rb'

         unless options.skip_recaptcha
           gem 'recaptcha', :require => "recaptcha/rails"
         end
         if options.use_airbrake
           gem 'airbrake'
         end

         gsub_file 'app/assets/javascripts/application.js',
                   '//= require turbolinks',
                   '//  require turbolinks'

         gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
         
         run_bundle
      end

# -------------------------------------------------------------
# -------------------------------------------------------------
      def setup_devise
        generate "devise:install"
        generate "devise", "user"
        gsub_file "app/models/user.rb", /,\s*$/, ", :confirmable,"

        migrate_user_file = find_or_fail("db/migrate/[0-9]*_devise_create_users.rb")

        uncomment_lines( migrate_user_file, /confirm/ )
        inject_into_file migrate_user_file, after: "# t.datetime :locked_at\n" do
          snippet_db_migrate_user
        end

        gsub_file 'config/initializers/devise.rb', /(config.mailer_sender = )'.+'/, "\1 #{options.org_email}"

      end

# -------------------------------------------------------------
# -------------------------------------------------------------
     def setup_milia

       unless false    # future skip block?? 

         route  snippet_routes_root_path

         generate "controller", "home index"
         generate "active_record:session_migration"
         generate "model", "tenant tenant:references name:string:index"
         generate "migration", "CreateTenantsUsersJoinTable tenants users"

         inject_into_file "app/controllers/application_controller.rb",
           after: "protect_from_forgery with: :exception\n" do 
           snippet_app_ctlr_header
         end
<commit_msg>generators - 22<commit_after>require 'rails/generators/base'

module Milia
  module Generators
# *************************************************************
    
    class InstallGenerator < Rails::Generators::Base
      desc "Full installation of milia with devise"

      source_root File.expand_path("../templates", __FILE__)
  
      class_option :use_airbrake, :type => :boolean, :default => false, :desc => 'Use this option to add airbrake exception handling capabilities'
      class_option :skip_recaptcha, :type => :boolean, :default => false, :desc => 'Use this option to skip adding recaptcha for sign ups'
      class_option :skip_invite_member, :type => :boolean, :default => false, :desc => 'Use this option to skip adding invite_member capabilities'
      class_option :skip_env_email_setup, :type => :boolean, :default => false, :desc => 'Use this option to skip adding smtp email info to config/environments/*'
      class_option :org_email, :type => :string, :default => "<EMAIL>", :desc => 'define the organizational email from address'
       
# -------------------------------------------------------------
# -------------------------------------------------------------
# -------------------------------------------------------------
# -------------------------------------------------------------
  def initialize_template_variables()
    @skip_recaptcha = options.skip_recaptcha
    @skip_invite_member = options.skip_invite_member
    @use_airbrake = options.use_airbrake
  end

# -------------------------------------------------------------
# the run('bundle install') didn't work; don't know why
# -------------------------------------------------------------
      def setup_initial_stuff

        template 'initializer.rb', 'config/initializers/milia.rb'

         unless options.skip_recaptcha
           gem 'recaptcha', :require => "recaptcha/rails"
         end
         if options.use_airbrake
           gem 'airbrake'
         end

         gsub_file 'app/assets/javascripts/application.js',
                   '//= require turbolinks',
                   '//  require turbolinks'

         gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
         
         run_bundle
      end

# -------------------------------------------------------------
# -------------------------------------------------------------
      def setup_devise
        generate "devise:install"
        generate "devise", "user"
        gsub_file "app/models/user.rb", /,\s*$/, ", :confirmable,"

        migrate_user_file = find_or_fail("db/migrate/[0-9]*_devise_create_users.rb")

        uncomment_lines( migrate_user_file, /confirm/ )
        inject_into_file migrate_user_file, after: "# t.datetime :locked_at\n" do
          snippet_db_migrate_user
        end

        gsub_file 'config/initializers/devise.rb', /config.mailer_sender = '.+'/, "config.mailer_sender = '#{options.org_email}'"

      end

# -------------------------------------------------------------
# -------------------------------------------------------------
     def setup_milia

       unless false    # future skip block?? 

         route  snippet_routes_root_path

         generate "controller", "home index"
         generate "active_record:session_migration"
         generate "model", "tenant tenant:references name:string:index"
         generate "migration", "CreateTenantsUsersJoinTable tenants users"

         inject_into_file "app/controllers/application_controller.rb",
           after: "protect_from_forgery with: :exception\n" do 
           snippet_app_ctlr_header
         end

{'fraction_non_alphanumeric': 0.26942286348501665, 'fraction_numerical': 0.0009711431742508325, 'mean_word_length': 1.6339057362075264, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '1548127', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1751, 'n_words': 417}