class RapidApi::SerializerAdapters::AmsAdapter
Public Instance Methods
deserialize_attributes(params, root_key)
click to toggle source
# File lib/rapid_api/serializer_adapters/ams_adapter.rb, line 26 def deserialize_attributes(params, root_key) #TODO: test attributes deserialization if ActiveModelSerializers.config.adapter == :attributes params.require(root_key) else attributes = params if params[:data][:attributes].present? attributes = params.require(:data).require(:attributes) end if params[:data][:relationships].present? relationships = params.require(:data).require(:relationships) relationships.keys.each do |attribute| attributes["#{attribute}_id"] = relationships[attribute][:data].try(:[], :id) end end attributes end end
deserialize_id(params, root_key)
click to toggle source
# File lib/rapid_api/serializer_adapters/ams_adapter.rb, line 45 def deserialize_id(params, root_key) params.require(:id) end
serialize(member)
click to toggle source
# File lib/rapid_api/serializer_adapters/ams_adapter.rb, line 5 def serialize(member) serializer = klass.new(member) ActiveModelSerializers::Adapter.create(serializer).to_json end
serialize_collection(collection)
click to toggle source
# File lib/rapid_api/serializer_adapters/ams_adapter.rb, line 10 def serialize_collection(collection) collection_serializer = ActiveModel::Serializer::CollectionSerializer.new collection, { serializer: klass } ActiveModelSerializers::Adapter.create(collection_serializer).to_json end
serialize_errors(query_result)
click to toggle source
# File lib/rapid_api/serializer_adapters/ams_adapter.rb, line 17 def serialize_errors(query_result) serializer = ActiveModel::Serializer::ErrorSerializer.new(query_result) if ActiveModelSerializers.config.adapter == :attributes { errors: serializer.as_json } else ActiveModelSerializers::Adapter.create(serializer).to_json end end