Class: JsonAPIObjectMapper::Deserializer::Resource
- Inherits:
-
Object
- Object
- JsonAPIObjectMapper::Deserializer::Resource
- Extended by:
- DSL
- Defined in:
- lib/jsonapi_object_mapper/deserializer/resource.rb
Constant Summary
Constants included from DSL
DSL::DEFAULT_ATTR_BLOCK, DSL::DEFAULT_HAS_ONE_BLOCK, DSL::DEFAULT_ID_BLOCK, DSL::DEFAULT_TYPE_BLOCK
Class Attribute Summary collapse
-
.attr_blocks ⇒ Object
Returns the value of attribute attr_blocks.
-
.rel_blocks ⇒ Object
Returns the value of attribute rel_blocks.
-
.rel_options ⇒ Object
Returns the value of attribute rel_options.
Class Method Summary collapse
- .call(document, parsed_includes = nil) ⇒ Object
- .call_collection(document) ⇒ Object
- .embed!(attributes) ⇒ Object
- .inherited(klass) ⇒ Object
Instance Method Summary collapse
-
#initialize(payload = nil, included = nil) ⇒ Resource
constructor
A new instance of Resource.
Methods included from DSL
attribute, attributes, extended, has_one, id, type
Constructor Details
#initialize(payload = nil, included = nil) ⇒ Resource
Returns a new instance of Resource.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 41 def initialize(payload = nil, included = nil) super() data = payload || {} @attributes = data["attributes"] || {} @relationships = data["relationships"] || {} @includes = IncludedResources.load(included) deserialize! freeze end |
Class Attribute Details
.attr_blocks ⇒ Object
Returns the value of attribute attr_blocks.
12 13 14 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 12 def attr_blocks @attr_blocks end |
.rel_blocks ⇒ Object
Returns the value of attribute rel_blocks.
12 13 14 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 12 def rel_blocks @rel_blocks end |
.rel_options ⇒ Object
Returns the value of attribute rel_options.
12 13 14 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 12 def @rel_options end |
Class Method Details
.call(document, parsed_includes = nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 31 def self.call(document, parsed_includes = nil) parsed_document = document.is_a?(Hash) ? document : ::Oj.load(document) parsed_includes ||= IncludedResources.load(parsed_document["included"]) new(parsed_document["data"], parsed_includes) end |
.call_collection(document) ⇒ Object
25 26 27 28 29 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 25 def self.call_collection(document) parsed_document = document.is_a?(Hash) ? document : ::Oj.load(document) parsed_includes = IncludedResources.load(parsed_document["included"]) Array(parsed_document["data"]).map { |doc| new(doc, parsed_includes) } end |
.embed!(attributes) ⇒ Object
37 38 39 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 37 def self.(attributes) new("attributes" => attributes) end |
.inherited(klass) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/jsonapi_object_mapper/deserializer/resource.rb', line 18 def self.inherited(klass) super klass.instance_variable_set("@attr_blocks", attr_blocks.dup) klass.instance_variable_set("@rel_blocks", rel_blocks.dup) klass.instance_variable_set("@rel_options", .dup) end |