@@ -2,51 +2,16 @@ module ActiveModelSerializers
2
2
module Adapter
3
3
class JsonApi < Base
4
4
extend ActiveSupport ::Autoload
5
- autoload :PaginationLinks
6
5
autoload :FragmentCache
7
- autoload :Link
8
- autoload :Meta
6
+ autoload :Jsonapi
9
7
autoload :ResourceIdentifier
10
8
autoload :Relationship
9
+ autoload :Link
10
+ autoload :PaginationLinks
11
+ autoload :Meta
11
12
autoload :Error
12
13
autoload :Deserialization
13
14
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
-
50
15
def initialize ( serializer , options = { } )
51
16
super
52
17
@include_tree = ActiveModel ::Serializer ::IncludeTree . from_include_args ( options [ :include ] )
@@ -74,7 +39,7 @@ def success_document(options)
74
39
hash [ :data ] = is_collection ? primary_data : primary_data [ 0 ]
75
40
hash [ :included ] = included if included . any?
76
41
77
- ApiObjects :: Jsonapi . add! ( hash )
42
+ Jsonapi . add! ( hash )
78
43
79
44
if instance_options [ :links ]
80
45
hash [ :links ] ||= { }
@@ -100,7 +65,7 @@ def success_document(options)
100
65
def failure_document
101
66
hash = { }
102
67
# PR Please :)
103
- # ApiObjects:: Jsonapi.add!(hash)
68
+ # Jsonapi.add!(hash)
104
69
105
70
if serializer . respond_to? ( :each )
106
71
hash [ :errors ] = serializer . flat_map do |error_serializer |
@@ -114,7 +79,7 @@ def failure_document
114
79
115
80
def fragment_cache ( cached_hash , non_cached_hash )
116
81
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 )
118
83
end
119
84
120
85
protected
@@ -217,7 +182,7 @@ def links_for(serializer)
217
182
218
183
# {http://jsonapi.org/format/#fetching-pagination Pagination Links}
219
184
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 )
221
186
end
222
187
223
188
# {http://jsonapi.org/format/#document-meta Docment Meta}
0 commit comments