@@ -2,51 +2,16 @@ module ActiveModelSerializers
22 module Adapter
33 class JsonApi < Base
44 extend ActiveSupport ::Autoload
5- autoload :PaginationLinks
65 autoload :FragmentCache
7- autoload :Link
8- autoload :Meta
6+ autoload :Jsonapi
97 autoload :ResourceIdentifier
108 autoload :Relationship
9+ autoload :Link
10+ autoload :PaginationLinks
11+ autoload :Meta
1112 autoload :Error
1213 autoload :Deserialization
1314
14- # TODO: if we like this abstraction and other API objects to it,
15- # then extract to its own file and require it.
16- module ApiObjects
17- # {http://jsonapi.org/format/#document-jsonapi-object Jsonapi Object}
18- module Jsonapi
19- ActiveModelSerializers . config . jsonapi_version = '1.0'
20- ActiveModelSerializers . config . jsonapi_toplevel_meta = { }
21- # Make JSON API top-level jsonapi member opt-in
22- # ref: http://jsonapi.org/format/#document-top-level
23- ActiveModelSerializers . config . jsonapi_include_toplevel_object = false
24-
25- module_function
26-
27- def add! ( hash )
28- hash . merge! ( object ) if include_object?
29- end
30-
31- def include_object?
32- ActiveModelSerializers . config . jsonapi_include_toplevel_object
33- end
34-
35- # TODO: see if we can cache this
36- def object
37- object = {
38- jsonapi : {
39- version : ActiveModelSerializers . config . jsonapi_version ,
40- meta : ActiveModelSerializers . config . jsonapi_toplevel_meta
41- }
42- }
43- object [ :jsonapi ] . reject! { |_ , v | v . blank? }
44-
45- object
46- end
47- end
48- end
49-
5015 def initialize ( serializer , options = { } )
5116 super
5217 @include_tree = ActiveModel ::Serializer ::IncludeTree . from_include_args ( options [ :include ] )
@@ -74,7 +39,7 @@ def success_document(options)
7439 hash [ :data ] = is_collection ? primary_data : primary_data [ 0 ]
7540 hash [ :included ] = included if included . any?
7641
77- ApiObjects :: Jsonapi . add! ( hash )
42+ Jsonapi . add! ( hash )
7843
7944 if instance_options [ :links ]
8045 hash [ :links ] ||= { }
@@ -100,7 +65,7 @@ def success_document(options)
10065 def failure_document
10166 hash = { }
10267 # PR Please :)
103- # ApiObjects:: Jsonapi.add!(hash)
68+ # Jsonapi.add!(hash)
10469
10570 if serializer . respond_to? ( :each )
10671 hash [ :errors ] = serializer . flat_map do |error_serializer |
@@ -114,7 +79,7 @@ def failure_document
11479
11580 def fragment_cache ( cached_hash , non_cached_hash )
11681 root = false if instance_options . include? ( :include )
117- ActiveModelSerializers :: Adapter :: JsonApi :: FragmentCache . new . fragment_cache ( root , cached_hash , non_cached_hash )
82+ FragmentCache . new . fragment_cache ( root , cached_hash , non_cached_hash )
11883 end
11984
12085 protected
@@ -217,7 +182,7 @@ def links_for(serializer)
217182
218183 # {http://jsonapi.org/format/#fetching-pagination Pagination Links}
219184 def pagination_links_for ( serializer , options )
220- JsonApi :: PaginationLinks . new ( serializer . object , options [ :serialization_context ] ) . serializable_hash ( options )
185+ PaginationLinks . new ( serializer . object , options [ :serialization_context ] ) . serializable_hash ( options )
221186 end
222187
223188 # {http://jsonapi.org/format/#document-meta Docment Meta}
0 commit comments