Sha256: ba7ab85a4b383fa3ae8a552e4a4c9d6e96376df1c1d186fac34ef85beba9e492

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "rails/railtie"
require_relative "crud_operations_logger"

module Rails
  module Crud
    module Tools
      # The Railtie class is responsible for adding custom initialization code to a Rails application.
      # It includes filters for logging CRUD operations in controllers and jobs.
      class Railtie < ::Rails::Railtie
        initializer "rails-crud.add_after_action" do
          ActiveSupport.on_load(:action_controller) do
            include Rails::Crud::Tools::OperationsLogger

            # 全てのコントローラにafter_actionフィルタを追加
            ActionController::Base.class_eval do
              around_action :log_crud_operations
            end

            # APIモードの場合はActionController::APIにも追加
            ActionController::API.class_eval do
              around_action :log_crud_operations
            end
          end

          # ActiveJobにもフィルタを追加
          ActiveSupport.on_load(:active_job) do
            include Rails::Crud::Tools::OperationsLogger

            # 全てのジョブにaround_performフィルタを追加
            ActiveJob::Base.class_eval do
              around_perform :log_crud_operations_for_job
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-crud-tools-0.6.10 lib/rails/crud/tools/railtie.rb
rails-crud-tools-0.6.9 lib/rails/crud/tools/railtie.rb