module ActionPolicy::Policy::Rails::Instrumentation
Add ActiveSupport::Notifications support.
Fires `action_policy.apply_rule` event on every `#apply` call. Fires `action_policy.init` event on every policy initialization.
Constants
- APPLY_EVENT_NAME
- INIT_EVENT_NAME
Public Class Methods
new(record = nil, **params)
click to toggle source
Calls superclass method
# File lib/action_policy/rails/policy/instrumentation.rb, line 14 def initialize(record = nil, **params) event = {policy: self.class.name} ActiveSupport::Notifications.instrument(INIT_EVENT_NAME, event) { super } end
Public Instance Methods
apply(rule)
click to toggle source
Calls superclass method
# File lib/action_policy/rails/policy/instrumentation.rb, line 19 def apply(rule) event = {policy: self.class.name, rule: rule.to_s} ActiveSupport::Notifications.instrument(APPLY_EVENT_NAME, event) do res = super event[:cached] = result.cached? event[:value] = result.value res end end