Class: ActionPolicy::LookupChain::NamespaceCache
- Inherits:
-
Object
- Object
- ActionPolicy::LookupChain::NamespaceCache
- Defined in:
- lib/action_policy/lookup_chain.rb
Overview
Cache namespace resolving result for policies.
Class Attribute Summary collapse
-
.store ⇒ Object
readonly
Returns the value of attribute store.
Class Method Summary collapse
- .clear ⇒ Object
- .fetch(namespace, policy, strict:, &block) ⇒ Object
- .put_if_absent(scope, namespace, policy) ⇒ Object
Class Attribute Details
.store ⇒ Object (readonly)
Returns the value of attribute store.
25 26 27 |
# File 'lib/action_policy/lookup_chain.rb', line 25 def store @store end |
Class Method Details
.clear ⇒ Object
43 44 45 46 |
# File 'lib/action_policy/lookup_chain.rb', line 43 def clear hash = Hash.new { |h, k| h[k] = {} } @store = {strict: hash, flexible: hash.clone} end |
.fetch(namespace, policy, strict:, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/action_policy/lookup_chain.rb', line 33 def fetch(namespace, policy, strict:, &block) return yield unless LookupChain.namespace_cache_enabled? if strict put_if_absent(:strict, namespace, policy, &block) else put_if_absent(:flexible, namespace, policy, &block) end end |
.put_if_absent(scope, namespace, policy) ⇒ Object
27 28 29 30 31 |
# File 'lib/action_policy/lookup_chain.rb', line 27 def put_if_absent(scope, namespace, policy) local_store = store[scope][namespace] return local_store[policy] if local_store[policy] local_store[policy] ||= yield end |