jsonapi-resources 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee2eb1bf17d93331630573c19708775eb1bb5379
|
4
|
+
data.tar.gz: 0e230d825047eebc973ad2b3c16a10d47c0ee54a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef3d97d1b89d5ceb0e585eddc32c7b69dfd6e3b60b96f4eb401634d4a1f32e65e7f75d11baa3f1a5adc1c66e2aa4a729b18f014bb084a775e9300a9e3ae933f
|
7
|
+
data.tar.gz: 7328baee52874231838085886f9d5280932c0f3950a93a9f001d9bdaf341c4a68000a1ae05700b60c7b429f283e53d6863f9bf7d811c9065aa4941a347f36197
|
@@ -16,7 +16,7 @@ class ActiveRecordOperationsProcessor < JSONAPI::OperationsProcessor
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def process_operation(operation)
|
19
|
-
operation.apply
|
19
|
+
operation.apply
|
20
20
|
rescue ActiveRecord::DeleteRestrictionError => e
|
21
21
|
record_locked_error = JSONAPI::Exceptions::RecordLocked.new(e.message)
|
22
22
|
return JSONAPI::ErrorsOperationResult.new(record_locked_error.errors[0].code, record_locked_error.errors)
|
data/lib/jsonapi/operation.rb
CHANGED
@@ -3,12 +3,13 @@ module JSONAPI
|
|
3
3
|
attr_reader :resource_klass, :options, :transactional
|
4
4
|
|
5
5
|
def initialize(resource_klass, options = {})
|
6
|
+
@context = options[:context]
|
6
7
|
@resource_klass = resource_klass
|
7
8
|
@options = options
|
8
9
|
@transactional = true
|
9
10
|
end
|
10
11
|
|
11
|
-
def apply
|
12
|
+
def apply
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -20,7 +21,8 @@ module JSONAPI
|
|
20
21
|
@include_directives = options[:include_directives]
|
21
22
|
@sort_criteria = options.fetch(:sort_criteria, [])
|
22
23
|
@paginator = options[:paginator]
|
23
|
-
|
24
|
+
@transactional = false
|
25
|
+
super(resource_klass, options)
|
24
26
|
end
|
25
27
|
|
26
28
|
def record_count
|
@@ -39,9 +41,9 @@ module JSONAPI
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
def apply
|
43
|
-
resource_records = @resource_klass.find(@resource_klass.verify_filters(@filters, context),
|
44
|
-
context: context,
|
44
|
+
def apply
|
45
|
+
resource_records = @resource_klass.find(@resource_klass.verify_filters(@filters, @context),
|
46
|
+
context: @context,
|
45
47
|
include_directives: @include_directives,
|
46
48
|
sort_criteria: @sort_criteria,
|
47
49
|
paginator: @paginator)
|
@@ -74,11 +76,11 @@ module JSONAPI
|
|
74
76
|
super(resource_klass, options)
|
75
77
|
end
|
76
78
|
|
77
|
-
def apply
|
78
|
-
key = @resource_klass.verify_key(@id, context)
|
79
|
+
def apply
|
80
|
+
key = @resource_klass.verify_key(@id, @context)
|
79
81
|
|
80
82
|
resource_record = resource_klass.find_by_key(key,
|
81
|
-
context: context,
|
83
|
+
context: @context,
|
82
84
|
include_directives: @include_directives)
|
83
85
|
|
84
86
|
return JSONAPI::ResourceOperationResult.new(:ok, resource_record)
|
@@ -98,8 +100,8 @@ module JSONAPI
|
|
98
100
|
super(resource_klass, options)
|
99
101
|
end
|
100
102
|
|
101
|
-
def apply
|
102
|
-
parent_resource = resource_klass.find_by_key(@parent_key, context: context)
|
103
|
+
def apply
|
104
|
+
parent_resource = resource_klass.find_by_key(@parent_key, context: @context)
|
103
105
|
|
104
106
|
return JSONAPI::LinksObjectOperationResult.new(:ok,
|
105
107
|
parent_resource,
|
@@ -121,8 +123,8 @@ module JSONAPI
|
|
121
123
|
super(resource_klass, options)
|
122
124
|
end
|
123
125
|
|
124
|
-
def apply
|
125
|
-
source_resource = @source_klass.find_by_key(@source_id, context: context)
|
126
|
+
def apply
|
127
|
+
source_resource = @source_klass.find_by_key(@source_id, context: @context)
|
126
128
|
|
127
129
|
related_resource = source_resource.send(@association_type)
|
128
130
|
|
@@ -147,8 +149,8 @@ module JSONAPI
|
|
147
149
|
super(resource_klass, options)
|
148
150
|
end
|
149
151
|
|
150
|
-
def apply
|
151
|
-
source_resource = @source_klass.find_by_key(@source_id, context: context)
|
152
|
+
def apply
|
153
|
+
source_resource = @source_klass.find_by_key(@source_id, context: @context)
|
152
154
|
|
153
155
|
related_resource = source_resource.send(@association_type,
|
154
156
|
{
|
@@ -172,8 +174,8 @@ module JSONAPI
|
|
172
174
|
super(resource_klass, options)
|
173
175
|
end
|
174
176
|
|
175
|
-
def apply
|
176
|
-
resource = @resource_klass.create(context)
|
177
|
+
def apply
|
178
|
+
resource = @resource_klass.create(@context)
|
177
179
|
result = resource.replace_fields(@data)
|
178
180
|
|
179
181
|
return JSONAPI::ResourceOperationResult.new((result == :completed ? :created : :accepted), resource)
|
@@ -190,8 +192,8 @@ module JSONAPI
|
|
190
192
|
super(resource_klass, options)
|
191
193
|
end
|
192
194
|
|
193
|
-
def apply
|
194
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
195
|
+
def apply
|
196
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
195
197
|
result = resource.remove
|
196
198
|
|
197
199
|
return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
|
@@ -210,8 +212,8 @@ module JSONAPI
|
|
210
212
|
super(resource_klass, options)
|
211
213
|
end
|
212
214
|
|
213
|
-
def apply
|
214
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
215
|
+
def apply
|
216
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
215
217
|
result = resource.replace_fields(data)
|
216
218
|
|
217
219
|
return JSONAPI::ResourceOperationResult.new(result == :completed ? :ok : :accepted, resource)
|
@@ -228,8 +230,8 @@ module JSONAPI
|
|
228
230
|
super(resource_klass, options)
|
229
231
|
end
|
230
232
|
|
231
|
-
def apply
|
232
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
233
|
+
def apply
|
234
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
233
235
|
result = resource.replace_has_one_link(@association_type, @key_value)
|
234
236
|
|
235
237
|
return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
|
@@ -246,8 +248,8 @@ module JSONAPI
|
|
246
248
|
super(resource_klass, options)
|
247
249
|
end
|
248
250
|
|
249
|
-
def apply
|
250
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
251
|
+
def apply
|
252
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
251
253
|
result = resource.create_has_many_links(@association_type, @data)
|
252
254
|
|
253
255
|
return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
|
@@ -264,8 +266,8 @@ module JSONAPI
|
|
264
266
|
super(resource_klass, options)
|
265
267
|
end
|
266
268
|
|
267
|
-
def apply
|
268
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
269
|
+
def apply
|
270
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
269
271
|
result = resource.replace_has_many_links(@association_type, @data)
|
270
272
|
|
271
273
|
return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
|
@@ -282,8 +284,8 @@ module JSONAPI
|
|
282
284
|
super(resource_klass, options)
|
283
285
|
end
|
284
286
|
|
285
|
-
def apply
|
286
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
287
|
+
def apply
|
288
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
287
289
|
result = resource.remove_has_many_link(@association_type, @associated_key)
|
288
290
|
|
289
291
|
return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
|
@@ -299,8 +301,8 @@ module JSONAPI
|
|
299
301
|
super(resource_klass, options)
|
300
302
|
end
|
301
303
|
|
302
|
-
def apply
|
303
|
-
resource = @resource_klass.find_by_key(@resource_id, context: context)
|
304
|
+
def apply
|
305
|
+
resource = @resource_klass.find_by_key(@resource_id, context: @context)
|
304
306
|
result = resource.remove_has_one_link(@association_type)
|
305
307
|
|
306
308
|
return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
|
@@ -27,7 +27,6 @@ module JSONAPI
|
|
27
27
|
def process(request)
|
28
28
|
@results = JSONAPI::OperationResults.new
|
29
29
|
@request = request
|
30
|
-
@context = request.context
|
31
30
|
@operations = request.operations
|
32
31
|
|
33
32
|
# Use transactions if more than one operation and if one of the operations can be transactional
|
@@ -82,7 +81,7 @@ module JSONAPI
|
|
82
81
|
end
|
83
82
|
|
84
83
|
def process_operation(operation)
|
85
|
-
operation.apply
|
84
|
+
operation.apply
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|
data/lib/jsonapi/request.rb
CHANGED
@@ -264,6 +264,7 @@ module JSONAPI
|
|
264
264
|
@operations.push JSONAPI::FindOperation.new(
|
265
265
|
@resource_klass,
|
266
266
|
{
|
267
|
+
context: @context,
|
267
268
|
filters: @filters,
|
268
269
|
include_directives: @include_directives,
|
269
270
|
sort_criteria: @sort_criteria,
|
@@ -276,6 +277,7 @@ module JSONAPI
|
|
276
277
|
@operations.push JSONAPI::ShowOperation.new(
|
277
278
|
@resource_klass,
|
278
279
|
{
|
280
|
+
context: @context,
|
279
281
|
id: @id,
|
280
282
|
include_directives: @include_directives
|
281
283
|
}
|
@@ -286,6 +288,7 @@ module JSONAPI
|
|
286
288
|
@operations.push JSONAPI::ShowAssociationOperation.new(
|
287
289
|
@resource_klass,
|
288
290
|
{
|
291
|
+
context: @context,
|
289
292
|
association_type: association_type,
|
290
293
|
parent_key: @resource_klass.verify_key(parent_key)
|
291
294
|
}
|
@@ -296,6 +299,7 @@ module JSONAPI
|
|
296
299
|
@operations.push JSONAPI::ShowRelatedResourceOperation.new(
|
297
300
|
@resource_klass,
|
298
301
|
{
|
302
|
+
context: @context,
|
299
303
|
association_type: association_type,
|
300
304
|
source_klass: @source_klass,
|
301
305
|
source_id: @source_id
|
@@ -307,6 +311,7 @@ module JSONAPI
|
|
307
311
|
@operations.push JSONAPI::ShowRelatedResourcesOperation.new(
|
308
312
|
@resource_klass,
|
309
313
|
{
|
314
|
+
context: @context,
|
310
315
|
association_type: association_type,
|
311
316
|
source_klass: @source_klass,
|
312
317
|
source_id: @source_id,
|
@@ -336,6 +341,7 @@ module JSONAPI
|
|
336
341
|
@operations.push JSONAPI::CreateResourceOperation.new(
|
337
342
|
@resource_klass,
|
338
343
|
{
|
344
|
+
context: @context,
|
339
345
|
data: data
|
340
346
|
}
|
341
347
|
)
|
@@ -519,6 +525,7 @@ module JSONAPI
|
|
519
525
|
@operations.push JSONAPI::CreateHasManyAssociationOperation.new(
|
520
526
|
resource_klass,
|
521
527
|
{
|
528
|
+
context: @context,
|
522
529
|
resource_id: parent_key,
|
523
530
|
association_type: association_type,
|
524
531
|
data: verified_param_set[:has_many].values[0]
|
@@ -537,6 +544,7 @@ module JSONAPI
|
|
537
544
|
@operations.push JSONAPI::ReplaceHasOneAssociationOperation.new(
|
538
545
|
resource_klass,
|
539
546
|
{
|
547
|
+
context: @context,
|
540
548
|
resource_id: parent_key,
|
541
549
|
association_type: association_type,
|
542
550
|
key_value: verified_param_set[:has_one].values[0]
|
@@ -553,6 +561,7 @@ module JSONAPI
|
|
553
561
|
@operations.push JSONAPI::ReplaceHasManyAssociationOperation.new(
|
554
562
|
resource_klass,
|
555
563
|
{
|
564
|
+
context: @context,
|
556
565
|
resource_id: parent_key,
|
557
566
|
association_type: association_type,
|
558
567
|
data: verified_param_set[:has_many].values[0]
|
@@ -585,6 +594,7 @@ module JSONAPI
|
|
585
594
|
@operations.push JSONAPI::ReplaceFieldsOperation.new(
|
586
595
|
@resource_klass,
|
587
596
|
{
|
597
|
+
context: @context,
|
588
598
|
resource_id: key,
|
589
599
|
data: parse_params(data, updatable_fields)
|
590
600
|
}
|
@@ -615,6 +625,7 @@ module JSONAPI
|
|
615
625
|
@operations.push JSONAPI::RemoveResourceOperation.new(
|
616
626
|
@resource_klass,
|
617
627
|
{
|
628
|
+
context: @context,
|
618
629
|
resource_id: key
|
619
630
|
}
|
620
631
|
)
|
@@ -637,6 +648,7 @@ module JSONAPI
|
|
637
648
|
@operations.push JSONAPI::RemoveHasManyAssociationOperation.new(
|
638
649
|
resource_klass,
|
639
650
|
{
|
651
|
+
context: @context,
|
640
652
|
resource_id: parent_key,
|
641
653
|
association_type: association_type,
|
642
654
|
associated_key: key
|
@@ -647,6 +659,7 @@ module JSONAPI
|
|
647
659
|
@operations.push JSONAPI::RemoveHasOneAssociationOperation.new(
|
648
660
|
resource_klass,
|
649
661
|
{
|
662
|
+
context: @context,
|
650
663
|
resource_id: parent_key,
|
651
664
|
association_type: association_type
|
652
665
|
}
|
data/lib/jsonapi/resource.rb
CHANGED
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.
|
4
|
+
version: 0.4.2
|
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: 2015-06-
|
12
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|