Sha256: 1ff0ce886ad3a0ee2483e68d258ba9bacb5eebf9bf4d897b94b91f22d829c6d7

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Boring
  module PaperTrail
    class InstallGenerator < Rails::Generators::Base
      desc "Adds paper trail to the application"
      source_root File.expand_path("templates", __dir__)

      class_option :skip_generator, type: :boolean, aliases: "-sg",
                   desc: "Skip running paper_trail install generator"
      class_option :skip_user_track_config, type: :boolean, aliases: "-sutc",
                   desc: "Skip adding config for tracking devise user in paper_trail"

      def add_bullet_gem
        say "Adding paper trail gems", :green
        Bundler.with_unbundled_env do
          run "bundle add paper_trail"
        end
      end

      def run_paper_trail_generator
        return if options[:skip_generator]

        say "Running rails_admin generator", :green
        Bundler.with_unbundled_env do
          run "DISABLE_SPRING=1 bundle exec rails generate paper_trail:install --with-changes"
        end
      end

      def set_configuration_to_track_whodunnit
        return if options[:skip_user_track_config]

        say "Setting configuration to track devise current_user", :green
        insert_into_file "app/controllers/application_controller.rb", <<~RUBY, after: /class ApplicationController < ActionController::Base/
          \tbefore_action :set_paper_trail_whodunnit
        RUBY
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boring_generators-0.15.0 lib/generators/boring/paper_trail/install/install_generator.rb
boring_generators-0.14.0 lib/generators/boring/paper_trail/install/install_generator.rb
boring_generators-0.13.0 lib/generators/boring/paper_trail/install/install_generator.rb
boring_generators-0.12.0 lib/generators/boring/paper_trail/install/install_generator.rb
boring_generators-0.11.0 lib/generators/boring/paper_trail/install/install_generator.rb