File tree Expand file tree Collapse file tree 2 files changed +12
-16
lines changed
lib/active_model/serializer Expand file tree Collapse file tree 2 files changed +12
-16
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,10 @@ def serializable_hash(options = nil)
29
29
end
30
30
end
31
31
32
- add_links ( options )
32
+ if serializer . paginated?
33
+ @hash [ :links ] ||= { }
34
+ @hash [ :links ] . update ( links_for ( serializer , options ) )
35
+ end
33
36
else
34
37
primary_data = primary_data_for ( serializer , options )
35
38
relationships = relationships_for ( serializer )
@@ -145,20 +148,7 @@ def _included_for(serializer, includes)
145
148
end
146
149
end
147
150
148
- def add_links ( options )
149
- links = @hash . fetch ( :links ) { { } }
150
- collection = serializer . object
151
- @hash [ :links ] = add_pagination_links ( links , collection , options ) if paginated? ( collection )
152
- end
153
-
154
- def add_pagination_links ( links , resources , options )
155
- pagination_links = ActiveModel ::Serializer ::Adapter ::JsonApi ::PaginationLinks . new ( resources , options [ :context ] ) . serializable_hash ( options )
156
- links . update ( pagination_links )
157
- end
158
-
159
- def paginated? ( collection )
160
- collection . respond_to? ( :current_page ) &&
161
- collection . respond_to? ( :total_pages ) &&
162
- collection . respond_to? ( :size )
151
+ def links_for ( serializer , options )
152
+ JsonApi ::PaginationLinks . new ( serializer . object , options [ :context ] ) . serializable_hash ( options )
163
153
end
164
154
end
Original file line number Diff line number Diff line change @@ -29,6 +29,12 @@ def json_key
29
29
key = root || @serializers . first . try ( :json_key ) || object . try ( :name ) . try ( :underscore )
30
30
key . try ( :pluralize )
31
31
end
32
+
33
+ def paginated?
34
+ object . respond_to? ( :current_page ) &&
35
+ object . respond_to? ( :total_pages ) &&
36
+ object . respond_to? ( :size )
37
+ end
32
38
end
33
39
end
34
40
end
You can’t perform that action at this time.
0 commit comments