class GraphQL::Pundit::Instrumenters::Scope::ScopeResolver
Applies the scoping to the passed object
Attributes
current_user[R]
field[R]
old_resolver[R]
scope[R]
Public Class Methods
new(current_user, scope, old_resolver, field)
click to toggle source
# File lib/graphql-pundit/instrumenters/scope.rb, line 14 def initialize(current_user, scope, old_resolver, field) @current_user = current_user @old_resolver = old_resolver @field = field raise ArgumentError, 'Invalid value passed to `scope`' unless valid_value?(scope) @scope = scope end
Private Instance Methods
find_scope(root, scope)
click to toggle source
# File lib/graphql-pundit/instrumenters/scope.rb, line 35 def find_scope(root, scope) if inferred?(scope) # Special case for Sequel datasets that do not respond to # ActiveModel's model_name infer_from = if root.respond_to?(:model) root.model else root end ::Pundit::PolicyFinder.new(infer_from).scope! else scope::Scope end end
inferred?(value)
click to toggle source
# File lib/graphql-pundit/instrumenters/scope.rb, line 58 def inferred?(value) value == :infer_scope end
new_scope(scope)
click to toggle source
# File lib/graphql-pundit/instrumenters/scope.rb, line 26 def new_scope(scope) return scope if proc?(scope) lambda do |root, _arguments, context| scope = find_scope(root, scope) scope.new(context[current_user], root).resolve end end
proc?(value)
click to toggle source
# File lib/graphql-pundit/instrumenters/scope.rb, line 54 def proc?(value) value.respond_to?(:call) end
valid_value?(value)
click to toggle source
# File lib/graphql-pundit/instrumenters/scope.rb, line 50 def valid_value?(value) value.is_a?(Class) || inferred?(value) || proc?(value) end