module GraphQL::Pundit::Scope
Public Class Methods
new(*args, before_scope: nil, after_scope: nil, **kwargs, &block)
click to toggle source
Calls superclass method
# File lib/graphql-pundit/scope.rb, line 13 def initialize(*args, before_scope: nil, after_scope: nil, **kwargs, &block) @before_scope = before_scope @after_scope = after_scope super(*args, **kwargs, &block) end
prepended(base)
click to toggle source
# File lib/graphql-pundit/scope.rb, line 9 def self.prepended(base) base.include(GraphQL::Pundit::Common) end
Public Instance Methods
after_scope(scope = true)
click to toggle source
# File lib/graphql-pundit/scope.rb, line 25 def after_scope(scope = true) @after_scope = scope end
before_scope(scope = true)
click to toggle source
# File lib/graphql-pundit/scope.rb, line 21 def before_scope(scope = true) @before_scope = scope end
resolve_field(obj, args, ctx)
click to toggle source
Calls superclass method
# File lib/graphql-pundit/scope.rb, line 29 def resolve_field(obj, args, ctx) before_scope_return = apply_scope(@before_scope, obj, args, ctx) field_return = super(before_scope_return, args, ctx) apply_scope(@after_scope, field_return, args, ctx) end
Private Instance Methods
apply_scope(scope, root, arguments, context)
click to toggle source
# File lib/graphql-pundit/scope.rb, line 37 def apply_scope(scope, root, arguments, context) return root unless scope return scope.call(root, arguments, context) if scope.respond_to?(:call) scope = infer_scope(root) if scope.equal?(true) scope::Scope.new(context[self.class.current_user], root).resolve end
infer_scope(root)
click to toggle source
# File lib/graphql-pundit/scope.rb, line 45 def infer_scope(root) infer_from = model?(root) ? root.model : root ::Pundit::PolicyFinder.new(infer_from).policy! end