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
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_blocks ⇒ Object
Returns the value of attribute rel_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_one, id, type
Methods included from Parser::Errors
Constructor Details
#initialize(parser, document: nil) ⇒ Resource
Returns a new instance of Resource.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 43 def initialize(parser, document: nil) super() raise InvalidParser, "Must provide a parsed document" 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_blocks ⇒ Object
Returns the value of attribute rel_blocks.
14 15 16 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 14 def rel_blocks @rel_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
29 30 31 32 33 34 35 36 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 29 def self.call(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 |
.embed!(attributes) ⇒ Object
38 39 40 41 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 38 def self.(attributes) parser = JsonAPIObjectMapper::Parser::Document.new("attributes" => attributes) new(parser) end |
.inherited(klass) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 20 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) klass.instance_variable_set("@id_block", id_block) klass.instance_variable_set("@type_block", type_block) end |
Instance Method Details
#each {|_self| ... } ⇒ Object
61 62 63 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 61 def each yield self end |