Class: ActiveAdmin::GraphQL::PolicySetCache
- Inherits:
-
Object
- Object
- ActiveAdmin::GraphQL::PolicySetCache
- Defined in:
- lib/active_admin/graphql/policy_set_cache.rb
Overview
Request-scoped memoization for ActiveAdmin policy sets on GraphQL objects.
Class Method Summary collapse
- .cache_key(subject_owner, subject) ⇒ Object
- .fetch(context, subject_owner:, subject:) ⇒ Object
- .policy_builder(context) ⇒ Object
Class Method Details
.cache_key(subject_owner, subject) ⇒ Object
35 36 37 38 |
# File 'lib/active_admin/graphql/policy_set_cache.rb', line 35 def cache_key(subject_owner, subject) owner_key = subject_owner_key(subject_owner) "#{owner_key}:#{subject_key(subject)}" end |
.fetch(context, subject_owner:, subject:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_admin/graphql/policy_set_cache.rb', line 8 def fetch(context, subject_owner:, subject:) namespace = context[:namespace] unless namespace return policy_builder(context).send( :build_policy_set, auth: context[:auth], subject_owner: subject_owner, subject: subject, context: context ) end cache = context[:policy_set_cache] ||= {} key = cache_key(subject_owner, subject) cache[key] ||= policy_builder(context).send( :build_policy_set, auth: context[:auth], subject_owner: subject_owner, subject: subject, context: context ) end |
.policy_builder(context) ⇒ Object
31 32 33 |
# File 'lib/active_admin/graphql/policy_set_cache.rb', line 31 def policy_builder(context) context[:policy_schema_builder] ||= SchemaBuilder.new(context[:namespace]) end |