Class: JsonAPIObjectMapper::Deserialize::Resource
- Inherits:
-
Object
- Object
- JsonAPIObjectMapper::Deserialize::Resource
- Extended by:
- DSL
- Includes:
- Parser::Errors
- Defined in:
- lib/jsonapi-object-mapper/deserialize/resource.rb
Constant Summary
Constants included from DSL
DSL::DEFAULT_BLOCK, DSL::HAS_MANY_BLOCK
Class Attribute Summary collapse
-
.attr_blocks ⇒ Object
Returns the value of attribute attr_blocks.
-
.id_block ⇒ Object
Returns the value of attribute id_block.
-
.rel_has_many_blocks ⇒ Object
Returns the value of attribute rel_has_many_blocks.
-
.rel_has_one_blocks ⇒ Object
Returns the value of attribute rel_has_one_blocks.
-
.rel_options ⇒ Object
Returns the value of attribute rel_options.
-
.type_block ⇒ Object
Returns the value of attribute type_block.
Attributes included from Parser::Errors
Class Method Summary collapse
Instance Method Summary collapse
- #each {|_self| ... } ⇒ Object
-
#initialize(parser, document: nil) ⇒ Resource
constructor
A new instance of Resource.
Methods included from DSL
attribute, attributes, extended, has_many, has_one, id, kind_of_resource?, type
Methods included from Parser::Errors
Constructor Details
#initialize(parser, document: nil) ⇒ Resource
Returns a new instance of Resource.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 44 def initialize(parser, document: nil) super() raise InvalidParser unless parser.is_a?(JsonAPIObjectMapper::Parser::Document) @errors = parser.errors if document_valid? @includes = parser.includes @data = document_data(parser, document) @id = @data["id"] @type = @data["type"] @attributes = @data.fetch("attributes", {}) @relationships = @data.fetch("relationships", {}) deserialize! end freeze end |
Class Attribute Details
.attr_blocks ⇒ Object
Returns the value of attribute attr_blocks.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def attr_blocks @attr_blocks end |
.id_block ⇒ Object
Returns the value of attribute id_block.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def id_block @id_block end |
.rel_has_many_blocks ⇒ Object
Returns the value of attribute rel_has_many_blocks.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def rel_has_many_blocks @rel_has_many_blocks end |
.rel_has_one_blocks ⇒ Object
Returns the value of attribute rel_has_one_blocks.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def rel_has_one_blocks @rel_has_one_blocks end |
.rel_options ⇒ Object
Returns the value of attribute rel_options.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def end |
.type_block ⇒ Object
Returns the value of attribute type_block.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def type_block @type_block end |
Class Method Details
.call(document) ⇒ Object
31 32 33 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 31 def self.call(document) load(document) end |
.inherited(klass) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 21 def self.inherited(klass) super klass.instance_variable_set("@attr_blocks", attr_blocks.dup) klass.instance_variable_set("@rel_has_one_blocks", rel_has_one_blocks.dup) klass.instance_variable_set("@rel_has_many_blocks", rel_has_many_blocks.dup) klass.instance_variable_set("@rel_options", .dup) klass.instance_variable_set("@id_block", id_block) klass.instance_variable_set("@type_block", type_block) end |
.load(document) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 35 def self.load(document) parser = JsonAPIObjectMapper::Parser::Document.new(document) if parser.document["data"].is_a?(Array) || parser.invalid? Collection.new(parser, klass: self) else new(parser) end end |
Instance Method Details
#each {|_self| ... } ⇒ Object
62 63 64 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 62 def each yield self end |