mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Update documentation with Yard links
This commit is contained in:
@@ -4,6 +4,10 @@ module ActiveModel
|
||||
class JsonApi
|
||||
module ApiObjects
|
||||
class Relationship
|
||||
# {http://jsonapi.org/format/#document-resource-object-related-resource-links Document Resource Object Related Resource Links}
|
||||
# {http://jsonapi.org/format/#document-links Document Links}
|
||||
# {http://jsonapi.org/format/#document-resource-object-linkage Document Resource Relationship Linkage}
|
||||
# {http://jsonapi.org/format/#document-meta Docment Meta}
|
||||
def initialize(parent_serializer, serializer, options = {}, links = {}, meta = nil)
|
||||
@object = parent_serializer.object
|
||||
@scope = parent_serializer.scope
|
||||
|
||||
@@ -4,6 +4,7 @@ module ActiveModel
|
||||
class JsonApi
|
||||
module ApiObjects
|
||||
class ResourceIdentifier
|
||||
# {http://jsonapi.org/format/#document-resource-identifier-objects Resource Identifier Objects}
|
||||
def initialize(serializer)
|
||||
@id = id_for(serializer)
|
||||
@type = type_for(serializer)
|
||||
|
||||
@@ -13,6 +13,7 @@ module ActiveModelSerializers
|
||||
# TODO: if we like this abstraction and other API objects to it,
|
||||
# then extract to its own file and require it.
|
||||
module ApiObjects
|
||||
# {http://jsonapi.org/format/#document-jsonapi-object Jsonapi Object}
|
||||
module Jsonapi
|
||||
ActiveModelSerializers.config.jsonapi_version = '1.0'
|
||||
ActiveModelSerializers.config.jsonapi_toplevel_meta = {}
|
||||
@@ -51,6 +52,8 @@ module ActiveModelSerializers
|
||||
@fieldset = options[:fieldset] || ActiveModel::Serializer::Fieldset.new(options.delete(:fields))
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#crud Requests are transactional, i.e. success or failure}
|
||||
# {http://jsonapi.org/format/#document-top-level data and errors MUST NOT coexist in the same document.}
|
||||
def serializable_hash(options = nil)
|
||||
options ||= {}
|
||||
if serializer.success?
|
||||
@@ -60,6 +63,7 @@ module ActiveModelSerializers
|
||||
end
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#document-top-level Primary data}
|
||||
def success_document(options)
|
||||
is_collection = serializer.respond_to?(:each)
|
||||
serializers = is_collection ? serializer : [serializer]
|
||||
@@ -84,6 +88,7 @@ module ActiveModelSerializers
|
||||
hash
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#errors JSON API Errors}
|
||||
# TODO: look into caching
|
||||
# rubocop:disable Style/AsciiComments
|
||||
# definition:
|
||||
@@ -117,6 +122,7 @@ module ActiveModelSerializers
|
||||
|
||||
private
|
||||
|
||||
# {http://jsonapi.org/format/#document-resource-objects Primary data}
|
||||
def resource_objects_for(serializers)
|
||||
@primary = []
|
||||
@included = []
|
||||
@@ -158,10 +164,12 @@ module ActiveModelSerializers
|
||||
process_relationships(serializer, include_tree)
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#document-resource-object-attributes Document Resource Object Attributes}
|
||||
def attributes_for(serializer, fields)
|
||||
serializer.attributes(fields).except(:id)
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#document-resource-objects Document Resource Objects}
|
||||
def resource_object_for(serializer)
|
||||
resource_object = cache_check(serializer) do
|
||||
resource_object = ActiveModel::Serializer::Adapter::JsonApi::ApiObjects::ResourceIdentifier.new(serializer).as_json
|
||||
@@ -185,6 +193,7 @@ module ActiveModelSerializers
|
||||
resource_object
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#document-resource-object-relationships Document Resource Object Relationship}
|
||||
def relationships_for(serializer, requested_associations)
|
||||
include_tree = ActiveModel::Serializer::IncludeTree.from_include_args(requested_associations)
|
||||
serializer.associations(include_tree).each_with_object({}) do |association, hash|
|
||||
@@ -198,16 +207,19 @@ module ActiveModelSerializers
|
||||
end
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#document-links Document Links}
|
||||
def links_for(serializer)
|
||||
serializer._links.each_with_object({}) do |(name, value), hash|
|
||||
hash[name] = Link.new(serializer, value).as_json
|
||||
end
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#fetching-pagination Pagination Links}
|
||||
def pagination_links_for(serializer, options)
|
||||
JsonApi::PaginationLinks.new(serializer.object, options[:serialization_context]).serializable_hash(options)
|
||||
end
|
||||
|
||||
# {http://jsonapi.org/format/#document-meta Docment Meta}
|
||||
def meta_for(serializer)
|
||||
ActiveModel::Serializer::Adapter::JsonApi::Meta.new(serializer).as_json
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user