Class: Graphiti::Runner
Instance Attribute Summary collapse
-
#deserialized_payload ⇒ Object
readonly
Returns the value of attribute deserialized_payload.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(resource_class, params, query = nil, action = nil) ⇒ Runner
constructor
A new instance of Runner.
-
#jsonapi_context ⇒ Object
Typically, this is ‘self’ of a controller We’re overriding here so we can do stuff like.
- #jsonapi_render_options ⇒ Object
- #jsonapi_resource ⇒ Object
- #jsonapi_scope(scope, opts = {}) ⇒ Object
- #proxy(base = nil, opts = {}) ⇒ Object
- #query ⇒ Object
- #query_hash ⇒ Object
- #wrap_context ⇒ Object
Constructor Details
#initialize(resource_class, params, query = nil, action = nil) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/graphiti/runner.rb', line 6 def initialize(resource_class, params, query = nil, action = nil) @resource_class = resource_class @params = params @query = query @action = action validator = RequestValidator.new(jsonapi_resource, params, action) validator.validate! @deserialized_payload = validator.deserialized_payload end |
Instance Attribute Details
#deserialized_payload ⇒ Object (readonly)
Returns the value of attribute deserialized_payload.
4 5 6 |
# File 'lib/graphiti/runner.rb', line 4 def deserialized_payload @deserialized_payload end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/graphiti/runner.rb', line 3 def params @params end |
Instance Method Details
#jsonapi_context ⇒ Object
28 29 30 |
# File 'lib/graphiti/runner.rb', line 28 def jsonapi_context Graphiti.context[:object] end |
#jsonapi_render_options ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/graphiti/runner.rb', line 50 def = {} .merge!() [:meta] ||= {} [:expose] ||= {} [:expose][:context] = jsonapi_context end |
#jsonapi_resource ⇒ Object
18 19 20 |
# File 'lib/graphiti/runner.rb', line 18 def jsonapi_resource @jsonapi_resource ||= @resource_class.new end |
#jsonapi_scope(scope, opts = {}) ⇒ Object
46 47 48 |
# File 'lib/graphiti/runner.rb', line 46 def jsonapi_scope(scope, opts = {}) jsonapi_resource.build_scope(scope, query, opts) end |
#proxy(base = nil, opts = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/graphiti/runner.rb', line 59 def proxy(base = nil, opts = {}) base ||= jsonapi_resource.base_scope scope_opts = opts.slice :sideload_parent_length, :default_paginate, :after_resolve, :sideload, :parent, :params, :bypass_required_filters scope = jsonapi_scope(base, scope_opts) ResourceProxy.new jsonapi_resource, scope, query, payload: deserialized_payload, single: opts[:single], raise_on_missing: opts[:raise_on_missing], cache: opts[:cache], cache_expires_in: opts[:cache_expires_in] end |
#query ⇒ Object
32 33 34 |
# File 'lib/graphiti/runner.rb', line 32 def query @query ||= Query.new(jsonapi_resource, params, nil, nil, [], @action) end |
#query_hash ⇒ Object
36 37 38 |
# File 'lib/graphiti/runner.rb', line 36 def query_hash @query_hash ||= query.hash end |
#wrap_context ⇒ Object
40 41 42 43 44 |
# File 'lib/graphiti/runner.rb', line 40 def wrap_context Graphiti.with_context(jsonapi_context, action_name.to_sym) do yield end end |