Class: JSONApi::Deserializer
- Inherits:
-
Object
- Object
- JSONApi::Deserializer
- Defined in:
- lib/jsonapi_deserializer.rb,
lib/jsonapi_deserializer/version.rb
Defined Under Namespace
Classes: Assocation, Record
Constant Summary collapse
- VERSION =
"1.1.1"
Instance Method Summary collapse
- #deserialized_hash ⇒ Object
-
#initialize(response) ⇒ Deserializer
constructor
A new instance of Deserializer.
Constructor Details
#initialize(response) ⇒ Deserializer
Returns a new instance of Deserializer.
23 24 25 26 27 28 29 30 |
# File 'lib/jsonapi_deserializer.rb', line 23 def initialize(response) @response = response.is_a?(Hash) ? response.with_indifferent_access : response @store = {} all_data = ([] << @response[:data] << @response[:included]).flatten.compact store_records(all_data) build_associations(all_data) end |
Instance Method Details
#deserialized_hash ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/jsonapi_deserializer.rb', line 32 def deserialized_hash data = @response[:data] if data.is_a? Array data.map { |datum| @store[datum[:type]][datum[:id].to_s] } else @store[data[:type]][data[:id].to_s] end end |