Sha256: 6465d5fe6225acb2c4004a6cdcdeb2b3f974addfb74f615436bd0733a378a45e
Contents?: true
Size: 1.59 KB
Versions: 57
Compression:
Stored size: 1.59 KB
Contents
module Graphiti module JsonapiSerializableExt # This library looks up a serializer based on the record's class name # This wouldn't work for us, since a model may be associated with # multiple resources. # Instead, this variable is assigned when the query is resolved # To ensure we always render with the *resource* serializer module RendererOverrides def _build(object, exposures, klass) resource = object.instance_variable_get(:@__graphiti_resource) klass = object.instance_variable_get(:@__graphiti_serializer) klass.new(exposures.merge(object: object, resource: resource)) end end # See above comment module RelationshipOverrides def data @_resources_block = proc do resources = yield if resources.nil? nil elsif resources.respond_to?(:to_ary) Array(resources).map do |obj| klass = obj.instance_variable_get(:@__graphiti_serializer) resource = obj.instance_variable_get(:@__graphiti_resource) klass.new(@_exposures.merge(object: obj, resource: resource)) end else klass = resources.instance_variable_get(:@__graphiti_serializer) resource = resources.instance_variable_get(:@__graphiti_resource) klass.new(@_exposures.merge(object: resources, resource: resource)) end end end end JSONAPI::Serializable::Relationship .send(:prepend, RelationshipOverrides) JSONAPI::Serializable::Renderer .send(:prepend, RendererOverrides) end end
Version data entries
57 entries across 57 versions & 1 rubygems