jsonapi-resources 0.8.3 → 0.9.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2124 -8
- data/lib/jsonapi-resources.rb +2 -0
- data/lib/jsonapi/acts_as_resource_controller.rb +70 -29
- data/lib/jsonapi/cached_resource_fragment.rb +119 -0
- data/lib/jsonapi/compiled_json.rb +36 -0
- data/lib/jsonapi/configuration.rb +54 -4
- data/lib/jsonapi/error_codes.rb +2 -2
- data/lib/jsonapi/exceptions.rb +19 -13
- data/lib/jsonapi/formatter.rb +15 -1
- data/lib/jsonapi/include_directives.rb +23 -3
- data/lib/jsonapi/processor.rb +69 -27
- data/lib/jsonapi/relationship_builder.rb +23 -21
- data/lib/jsonapi/request_parser.rb +27 -72
- data/lib/jsonapi/resource.rb +234 -38
- data/lib/jsonapi/resource_serializer.rb +229 -95
- data/lib/jsonapi/resources/version.rb +1 -1
- data/lib/jsonapi/response_document.rb +9 -20
- metadata +25 -9
@@ -1,7 +1,8 @@
|
|
1
1
|
module JSONAPI
|
2
2
|
class ResponseDocument
|
3
|
-
def initialize(operation_results, options = {})
|
3
|
+
def initialize(operation_results, serializer, options = {})
|
4
4
|
@operation_results = operation_results
|
5
|
+
@serializer = serializer
|
5
6
|
@options = options
|
6
7
|
|
7
8
|
@key_formatter = @options.fetch(:key_formatter, JSONAPI.configuration.key_formatter)
|
@@ -29,18 +30,6 @@ module JSONAPI
|
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
def serializer
|
33
|
-
@serializer ||= @options.fetch(:resource_serializer_klass, JSONAPI::ResourceSerializer).new(
|
34
|
-
@options.fetch(:primary_resource_klass),
|
35
|
-
include_directives: @options[:include_directives],
|
36
|
-
fields: @options[:fields],
|
37
|
-
base_url: @options.fetch(:base_url, ''),
|
38
|
-
key_formatter: @key_formatter,
|
39
|
-
route_formatter: @options.fetch(:route_formatter, JSONAPI.configuration.route_formatter),
|
40
|
-
serialization_options: @options.fetch(:serialization_options, {})
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
33
|
# Rolls up the top level meta data from the base_meta, the set of operations,
|
45
34
|
# and the result of each operation. The keys are then formatted.
|
46
35
|
def top_level_meta
|
@@ -60,7 +49,7 @@ module JSONAPI
|
|
60
49
|
end
|
61
50
|
end
|
62
51
|
|
63
|
-
meta.deep_transform_keys { |key| @key_formatter.format(key) }
|
52
|
+
meta.as_json.deep_transform_keys { |key| @key_formatter.format(key) }
|
64
53
|
end
|
65
54
|
|
66
55
|
# Rolls up the top level links from the base_links, the set of operations,
|
@@ -78,9 +67,9 @@ module JSONAPI
|
|
78
67
|
result.pagination_params.each_pair do |link_name, params|
|
79
68
|
if result.is_a?(JSONAPI::RelatedResourcesOperationResult)
|
80
69
|
relationship = result.source_resource.class._relationships[result._type.to_sym]
|
81
|
-
links[link_name] = serializer.link_builder.relationships_related_link(result.source_resource, relationship, query_params(params))
|
70
|
+
links[link_name] = @serializer.link_builder.relationships_related_link(result.source_resource, relationship, query_params(params))
|
82
71
|
else
|
83
|
-
links[link_name] = serializer.query_link(query_params(params))
|
72
|
+
links[link_name] = @serializer.query_link(query_params(params))
|
84
73
|
end
|
85
74
|
end
|
86
75
|
end
|
@@ -117,11 +106,11 @@ module JSONAPI
|
|
117
106
|
|
118
107
|
case result
|
119
108
|
when JSONAPI::ResourceOperationResult
|
120
|
-
serializer.serialize_to_hash(result.resource)
|
109
|
+
@serializer.serialize_to_hash(result.resource)
|
121
110
|
when JSONAPI::ResourcesOperationResult
|
122
|
-
serializer.serialize_to_hash(result.resources)
|
111
|
+
@serializer.serialize_to_hash(result.resources)
|
123
112
|
when JSONAPI::LinksObjectOperationResult
|
124
|
-
serializer.serialize_to_links_hash(result.parent_resource,
|
113
|
+
@serializer.serialize_to_links_hash(result.parent_resource,
|
125
114
|
result.relationship)
|
126
115
|
when JSONAPI::OperationResult
|
127
116
|
{}
|
@@ -138,7 +127,7 @@ module JSONAPI
|
|
138
127
|
end
|
139
128
|
end
|
140
129
|
|
141
|
-
serializer.serialize_to_hash(resources)
|
130
|
+
@serializer.serialize_to_hash(resources)
|
142
131
|
end
|
143
132
|
end
|
144
133
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -110,19 +110,33 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: activerecord
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '4.
|
118
|
+
version: '4.1'
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '4.
|
125
|
+
version: '4.1'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: railties
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '4.1'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '4.1'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: concurrent-ruby
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,7 +169,9 @@ files:
|
|
155
169
|
- lib/generators/jsonapi/templates/jsonapi_resource.rb
|
156
170
|
- lib/jsonapi-resources.rb
|
157
171
|
- lib/jsonapi/acts_as_resource_controller.rb
|
172
|
+
- lib/jsonapi/cached_resource_fragment.rb
|
158
173
|
- lib/jsonapi/callbacks.rb
|
174
|
+
- lib/jsonapi/compiled_json.rb
|
159
175
|
- lib/jsonapi/configuration.rb
|
160
176
|
- lib/jsonapi/error.rb
|
161
177
|
- lib/jsonapi/error_codes.rb
|
@@ -193,15 +209,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
209
|
requirements:
|
194
210
|
- - ">="
|
195
211
|
- !ruby/object:Gem::Version
|
196
|
-
version: '2.
|
212
|
+
version: '2.1'
|
197
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
214
|
requirements:
|
199
|
-
- - "
|
215
|
+
- - ">"
|
200
216
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
217
|
+
version: 1.3.1
|
202
218
|
requirements: []
|
203
219
|
rubyforge_project:
|
204
|
-
rubygems_version: 2.
|
220
|
+
rubygems_version: 2.5.1
|
205
221
|
signing_key:
|
206
222
|
specification_version: 4
|
207
223
|
summary: Easily support JSON API in Rails.
|