Sha256: 115755ed37cde5d5f7620f416696faef8ba33939df4ed93d308496ba74330dac

Contents?: true

Size: 714 Bytes

Versions: 2

Compression:

Stored size: 714 Bytes

Contents

require 'pundit'
require 'set'

module ::Pundit
  class PolicyFinder
    alias_method :original_scope, :scope
    def scope
      policy_scope_class = original_scope
      policy_scope_class_invoked policy_scope_class
      policy_scope_class
    end

    private

    def policy_scope_class_invoked(policy_scope_class)
      return unless policy_scope_class
      Pundit.invoked_policy_scope_names << policy_scope_class.name

      return unless Pundit::Logger.log_scope_instantiation?
      Pundit::Logger.log "Invoking #{policy_scope_class.name}"
    end
  end

  class << self
    def invoked_policy_scope_names
      @invoked_policy_scope_names ||= Set.new
      @invoked_policy_scope_names
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pundit_logger-0.1.1 lib/pundit_extensions/loggers.rb
pundit_logger-0.1.0 lib/pundit_extensions/loggers.rb