Sha256: c618081ec22ecf727646b8e3f8c22a82d4645b173be93f5457bddcadbb23c3af

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

require 'rails/railtie'
require_relative 'crud_operations_logger'

module Rails
  module Crud
    module Tools
      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

6 entries across 6 versions & 1 rubygems

Version Path
rails-crud-tools-0.6.0 lib/rails/crud/tools/railtie.rb
rails-crud-tools-0.5.0 lib/rails/crud/tools/railtie.rb
rails-crud-tools-0.4.3 lib/rails/crud/tools/railtie.rb
rails-crud-tools-0.4.2 lib/rails/crud/tools/railtie.rb
rails-crud-tools-0.4.1 lib/rails/crud/tools/railtie.rb
rails-crud-tools-0.4.0 lib/rails/crud/tools/railtie.rb