Skip to content

Commit 79cd4e2

Browse files
committed
Update documentation with Yard links
1 parent 3d98637 commit 79cd4e2

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

docs/jsonapi/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Back to Guides](../README.md)
22

3-
# JSON API Errors
3+
# [JSON API Errors](http://jsonapi.org/format/#errors)
44

55
Rendering error documents requires specifying the error serializer(s):
66

lib/active_model/serializer/adapter/json_api/api_objects/relationship.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ module Adapter
44
class JsonApi
55
module ApiObjects
66
class Relationship
7+
# {http://jsonapi.org/format/#document-resource-object-related-resource-links Document Resource Object Related Resource Links}
8+
# {http://jsonapi.org/format/#document-links Document Links}
9+
# {http://jsonapi.org/format/#document-resource-object-linkage Document Resource Relationship Linkage}
10+
# {http://jsonapi.org/format/#document-meta Docment Meta}
711
def initialize(parent_serializer, serializer, options = {}, links = {}, meta = nil)
812
@object = parent_serializer.object
913
@scope = parent_serializer.scope

lib/active_model/serializer/adapter/json_api/api_objects/resource_identifier.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Adapter
44
class JsonApi
55
module ApiObjects
66
class ResourceIdentifier
7+
# {http://jsonapi.org/format/#document-resource-identifier-objects Resource Identifier Objects}
78
def initialize(serializer)
89
@id = id_for(serializer)
910
@type = type_for(serializer)

lib/active_model_serializers/adapter/json_api.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class JsonApi < Base
1313
# TODO: if we like this abstraction and other API objects to it,
1414
# then extract to its own file and require it.
1515
module ApiObjects
16+
# {http://jsonapi.org/format/#document-jsonapi-object Jsonapi Object}
1617
module Jsonapi
1718
ActiveModelSerializers.config.jsonapi_version = '1.0'
1819
ActiveModelSerializers.config.jsonapi_toplevel_meta = {}
@@ -51,6 +52,8 @@ def initialize(serializer, options = {})
5152
@fieldset = options[:fieldset] || ActiveModel::Serializer::Fieldset.new(options.delete(:fields))
5253
end
5354

55+
# {http://jsonapi.org/format/#crud Requests are transactional, i.e. success or failure}
56+
# {http://jsonapi.org/format/#document-top-level data and errors MUST NOT coexist in the same document.}
5457
def serializable_hash(options = nil)
5558
options ||= {}
5659
if serializer.success?
@@ -60,6 +63,7 @@ def serializable_hash(options = nil)
6063
end
6164
end
6265

66+
# {http://jsonapi.org/format/#document-top-level Primary data}
6367
def success_document(options)
6468
is_collection = serializer.respond_to?(:each)
6569
serializers = is_collection ? serializer : [serializer]
@@ -84,6 +88,7 @@ def success_document(options)
8488
hash
8589
end
8690

91+
# {http://jsonapi.org/format/#errors JSON API Errors}
8792
# TODO: look into caching
8893
# rubocop:disable Style/AsciiComments
8994
# definition:
@@ -117,6 +122,7 @@ def fragment_cache(cached_hash, non_cached_hash)
117122

118123
private
119124

125+
# {http://jsonapi.org/format/#document-resource-objects Primary data}
120126
def resource_objects_for(serializers)
121127
@primary = []
122128
@included = []
@@ -158,10 +164,12 @@ def process_relationship(serializer, include_tree)
158164
process_relationships(serializer, include_tree)
159165
end
160166

167+
# {http://jsonapi.org/format/#document-resource-object-attributes Document Resource Object Attributes}
161168
def attributes_for(serializer, fields)
162169
serializer.attributes(fields).except(:id)
163170
end
164171

172+
# {http://jsonapi.org/format/#document-resource-objects Document Resource Objects}
165173
def resource_object_for(serializer)
166174
resource_object = cache_check(serializer) do
167175
resource_object = ActiveModel::Serializer::Adapter::JsonApi::ApiObjects::ResourceIdentifier.new(serializer).as_json
@@ -185,6 +193,7 @@ def resource_object_for(serializer)
185193
resource_object
186194
end
187195

196+
# {http://jsonapi.org/format/#document-resource-object-relationships Document Resource Object Relationship}
188197
def relationships_for(serializer, requested_associations)
189198
include_tree = ActiveModel::Serializer::IncludeTree.from_include_args(requested_associations)
190199
serializer.associations(include_tree).each_with_object({}) do |association, hash|
@@ -198,16 +207,19 @@ def relationships_for(serializer, requested_associations)
198207
end
199208
end
200209

210+
# {http://jsonapi.org/format/#document-links Document Links}
201211
def links_for(serializer)
202212
serializer._links.each_with_object({}) do |(name, value), hash|
203213
hash[name] = Link.new(serializer, value).as_json
204214
end
205215
end
206216

217+
# {http://jsonapi.org/format/#fetching-pagination Pagination Links}
207218
def pagination_links_for(serializer, options)
208219
JsonApi::PaginationLinks.new(serializer.object, options[:serialization_context]).serializable_hash(options)
209220
end
210221

222+
# {http://jsonapi.org/format/#document-meta Docment Meta}
211223
def meta_for(serializer)
212224
ActiveModel::Serializer::Adapter::JsonApi::Meta.new(serializer).as_json
213225
end

0 commit comments

Comments
 (0)