Method: LogicalModel.from_json

Defined in:
lib/logical_model/rest_actions.rb

.from_json(json_string) ⇒ Object

Will parse JSON string and initialize classes for all hashes in json_string.



423
424
425
426
427
428
429
430
431
432
433
# File 'lib/logical_model/rest_actions.rb', line 423

def self.from_json(json_string)
  parsed_response = ActiveSupport::JSON.decode(json_string)
  parsed_collection = collection_key.nil?? parsed_response : parsed_response[collection_key]
  collection = parsed_collection.map{|i| self.new(i)}

  if total_key
    {collection: collection, total: parsed_response[total_key].to_i}
  else
    { collection: collection }
  end
end