Class: JsonAPIObjectMapper::Deserializer::IncludedResources
- Inherits:
-
Object
- Object
- JsonAPIObjectMapper::Deserializer::IncludedResources
- Extended by:
- Forwardable
- Defined in:
- lib/jsonapi_object_mapper/deserializer/included_resources.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(relationship) ⇒ Object
- #format_key(relationship) ⇒ Object
- #included?(relationship) ⇒ Boolean
-
#initialize(included_resources = []) ⇒ IncludedResources
constructor
A new instance of IncludedResources.
Constructor Details
#initialize(included_resources = []) ⇒ IncludedResources
Returns a new instance of IncludedResources.
16 17 18 19 20 21 22 |
# File 'lib/jsonapi_object_mapper/deserializer/included_resources.rb', line 16 def initialize(included_resources = []) included_resources ||= [] @resource = included_resources.each_with_object({}) do |include, hash| hash[format_key(include)] = include["attributes"] end end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
8 9 10 |
# File 'lib/jsonapi_object_mapper/deserializer/included_resources.rb', line 8 def resource @resource end |
Class Method Details
.load(included_resources) ⇒ Object
11 12 13 14 |
# File 'lib/jsonapi_object_mapper/deserializer/included_resources.rb', line 11 def self.load(included_resources) return included_resources if included_resources.is_a?(self) new included_resources end |
Instance Method Details
#fetch(relationship) ⇒ Object
24 25 26 |
# File 'lib/jsonapi_object_mapper/deserializer/included_resources.rb', line 24 def fetch(relationship) @resource.fetch(format_key(relationship), relationship) end |
#format_key(relationship) ⇒ Object
32 33 34 |
# File 'lib/jsonapi_object_mapper/deserializer/included_resources.rb', line 32 def format_key(relationship) "#{relationship['type']}:#{relationship['id']}" end |
#included?(relationship) ⇒ Boolean
28 29 30 |
# File 'lib/jsonapi_object_mapper/deserializer/included_resources.rb', line 28 def included?(relationship) @resource.key?(format_key(relationship)) end |