Module: ActionPolicy::Policy::CachedApply

Included in:
Base
Defined in:
lib/action_policy/policy/cached_apply.rb

Overview

Per-policy cache for applied rules.

When you call ‘apply` twice on the same policy and for the same rule, the check (and pre-checks) is only called once.

Instance Method Summary collapse

Instance Method Details

#apply_r(rule) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/action_policy/policy/cached_apply.rb', line 10

def apply_r(rule)
  @__rules_cache__ ||= {}

  if @__rules_cache__.key?(rule)
    return @__rules_cache__[rule]
  end

  super.tap do |result|
    @__rules_cache__[rule] = result
  end
end