Class: Giraph::Resolver
- Inherits:
-
Object
- Object
- Giraph::Resolver
- Defined in:
- lib/giraph/resolver.rb
Overview
Proc-like class to allow declerative links to external resolution handlers (so the “definition” gem can stay pure resolution-wise)
Defined Under Namespace
Classes: UnknownOperation
Class Method Summary collapse
Instance Method Summary collapse
-
#call(obj, args, ctx) ⇒ Object
Resolves the field by calling the previously given method on the registered Resolver object for the current operation type (currently query or mutation).
-
#initialize(method_name) ⇒ Resolver
constructor
A new instance of Resolver.
Constructor Details
#initialize(method_name) ⇒ Resolver
Returns a new instance of Resolver.
11 12 13 |
# File 'lib/giraph/resolver.rb', line 11 def initialize(method_name) @method_name = method_name end |
Class Method Details
.for(method_name) ⇒ Object
7 8 9 |
# File 'lib/giraph/resolver.rb', line 7 def self.for(method_name) new(method_name) end |
Instance Method Details
#call(obj, args, ctx) ⇒ Object
Resolves the field by calling the previously given method on the registered Resolver object for the current operation type (currently query or mutation)
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/giraph/resolver.rb', line 18 def call(obj, args, ctx) # Find out operation type (query, mutation, etc.) op_type = ctx.query.selected_operation.operation_type.to_sym # Ensure there is a registered resolver for it unless (resolver = ctx[:__giraph_resolver__][op_type]) raise UnknownOperation, "No resolver found for '#{op_type}' op type" end # Call the requested method on resolver resolver.public_send(@method_name, obj, args, ctx) end |