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.
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 46 def initialize(parser, document: nil) super() raise InvalidParser unless parser.is_a?(JsonAPIObjectMapper::Parser::Document) @errors = parser.errors if document_valid? @includes = parser.includes @links = parser_links(parser) @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.
16 17 18 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 16 def attr_blocks @attr_blocks end |
.id_block ⇒ Object
Returns the value of attribute id_block.
16 17 18 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 16 def id_block @id_block end |
.rel_has_many_blocks ⇒ Object
Returns the value of attribute rel_has_many_blocks.
16 17 18 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 16 def rel_has_many_blocks @rel_has_many_blocks end |
.rel_has_one_blocks ⇒ Object
Returns the value of attribute rel_has_one_blocks.
16 17 18 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 16 def rel_has_one_blocks @rel_has_one_blocks end |
.rel_options ⇒ Object
Returns the value of attribute rel_options.
16 17 18 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 16 def @rel_options end |
.type_block ⇒ Object
Returns the value of attribute type_block.
16 17 18 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 16 def type_block @type_block end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
13 14 15 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 13 def links @links end |
Class Method Details
.call(document) ⇒ Object
33 34 35 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 33 def self.call(document) load(document) end |
.inherited(klass) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 23 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
37 38 39 40 41 42 43 44 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 37 def self.load(document) parser = JsonAPIObjectMapper::Parser::Document.new(document) if parser.contains_data_array? || parser.invalid? Collection.new(parser, klass: self) else new(parser) end end |
Instance Method Details
#each {|_self| ... } ⇒ Object
65 66 67 |
# File 'lib/jsonapi-object-mapper/deserialize/resource.rb', line 65 def each yield self end |