Class: SimpleJSONAPIDeserializer::Resource
- Inherits:
-
Object
- Object
- SimpleJSONAPIDeserializer::Resource
- Defined in:
- lib/simple_jsonapi_deserializer/resource.rb,
lib/simple_jsonapi_deserializer/resource/cache.rb,
lib/simple_jsonapi_deserializer/resource/includes.rb
Defined Under Namespace
Instance Method Summary collapse
- #deserialize(without_attributes: false, without_relationships: false) ⇒ Object
- #id ⇒ Object
-
#initialize(resource, includes, cache) ⇒ Resource
constructor
A new instance of Resource.
- #type ⇒ Object
Constructor Details
#initialize(resource, includes, cache) ⇒ Resource
Returns a new instance of Resource.
3 4 5 6 7 |
# File 'lib/simple_jsonapi_deserializer/resource.rb', line 3 def initialize(resource, includes, cache) @resource = resource @includes = includes @cache = cache end |
Instance Method Details
#deserialize(without_attributes: false, without_relationships: false) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/simple_jsonapi_deserializer/resource.rb', line 9 def deserialize(without_attributes: false, without_relationships: false) {}.tap do |deserialized_resource| deserialized_resource.merge!(attributes) unless without_attributes deserialized_resource.merge!(deserialized_relationships) unless without_relationships deserialized_resource['type'] = type if type deserialized_resource['id'] = id if id end end |
#id ⇒ Object
18 19 20 |
# File 'lib/simple_jsonapi_deserializer/resource.rb', line 18 def id resource['id'] end |
#type ⇒ Object
22 23 24 |
# File 'lib/simple_jsonapi_deserializer/resource.rb', line 22 def type resource['type'] end |