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, Store
Constant Summary collapse
- VERSION =
"1.3.0"
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.
62 63 64 65 66 67 68 69 |
# File 'lib/jsonapi_deserializer.rb', line 62 def initialize(response) @response = response.is_a?(Hash) ? response.with_indifferent_access : response @store = Store.new all_data = ([] << @response[:data] << @response[:included]).flatten.compact store_records(all_data) build_associations(all_data) end |
Instance Method Details
#deserialized_hash ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/jsonapi_deserializer.rb', line 71 def deserialized_hash data = @response[:data] if data.is_a? Array data.map { |datum| @store.get(datum[:type], datum[:id], datum[:lid]) } else @store.get(data[:type], data[:id], data[:lid]) end end |