jsonapi_compliable 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi_compliable/adapters/active_record_sideloading.rb +11 -5
- data/lib/jsonapi_compliable/deserializable.rb +1 -1
- data/lib/jsonapi_compliable/scope.rb +3 -1
- data/lib/jsonapi_compliable/scoping/base.rb +11 -2
- data/lib/jsonapi_compliable/scoping/paginate.rb +8 -0
- data/lib/jsonapi_compliable/sideload.rb +1 -1
- data/lib/jsonapi_compliable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51079670b0c1dedbb613140f18d466467aac8176
|
4
|
+
data.tar.gz: 25aa3bb0cafd200e8508d7e9492ca6334f2451d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11eafba78c92d9b13d547b0ab43d6fec831a4f0f872c79d122a289f76be3a22dd16c53e78fb7f2a242c6b4bec92b3795fd3c0d8a8fee4b7d75788572200a938
|
7
|
+
data.tar.gz: a654eea7228308a1a057522fa6c0b5783a93c7644ef4c5b444100a1c543cfc3365e03a40d5f8aa9038b8557790dcfd60067ad8e0f6665e04a4636ec0f40dc1fa
|
@@ -7,7 +7,7 @@ module JsonapiCompliable
|
|
7
7
|
allow_sideload association_name, resource: resource do
|
8
8
|
scope do |parents|
|
9
9
|
parent_ids = parents.map { |p| p.send(primary_key) }
|
10
|
-
_scope.call.where(foreign_key => parent_ids)
|
10
|
+
_scope.call.where(foreign_key => parent_ids.uniq.compact)
|
11
11
|
end
|
12
12
|
|
13
13
|
assign do |parents, children|
|
@@ -30,7 +30,7 @@ module JsonapiCompliable
|
|
30
30
|
allow_sideload association_name, resource: resource do
|
31
31
|
scope do |parents|
|
32
32
|
parent_ids = parents.map { |p| p.send(foreign_key) }
|
33
|
-
_scope.call.where(primary_key => parent_ids)
|
33
|
+
_scope.call.where(primary_key => parent_ids.uniq.compact)
|
34
34
|
end
|
35
35
|
|
36
36
|
assign do |parents, children|
|
@@ -50,7 +50,7 @@ module JsonapiCompliable
|
|
50
50
|
allow_sideload association_name, resource: resource do
|
51
51
|
scope do |parents|
|
52
52
|
parent_ids = parents.map { |p| p.send(primary_key) }
|
53
|
-
_scope.call.where(foreign_key => parent_ids)
|
53
|
+
_scope.call.where(foreign_key => parent_ids.uniq.compact)
|
54
54
|
end
|
55
55
|
|
56
56
|
assign do |parents, children|
|
@@ -73,7 +73,10 @@ module JsonapiCompliable
|
|
73
73
|
|
74
74
|
allow_sideload association_name, resource: resource do
|
75
75
|
scope do |parents|
|
76
|
-
|
76
|
+
parent_ids = parents.map { |p| p.send(primary_key) }
|
77
|
+
parent_ids.uniq!
|
78
|
+
parent_ids.compact!
|
79
|
+
_scope.call.joins(through).where(through => { fk => parent_ids })
|
77
80
|
end
|
78
81
|
|
79
82
|
assign do |parents, children|
|
@@ -100,7 +103,10 @@ module JsonapiCompliable
|
|
100
103
|
|
101
104
|
allow_sideload type, resource: config[:resource] do
|
102
105
|
scope do |parents|
|
103
|
-
|
106
|
+
parent_ids = parents.map { |p| p.send(foreign_key) }
|
107
|
+
parent_ids.compact!
|
108
|
+
parent_ids.uniq!
|
109
|
+
config[:scope].call.where(primary_key => parent_ids)
|
104
110
|
end
|
105
111
|
|
106
112
|
assign do |parents, children|
|
@@ -61,7 +61,7 @@ module JsonapiCompliable
|
|
61
61
|
hash = attributes
|
62
62
|
hash = hash.merge(relationships)
|
63
63
|
hash = @namespace ? { parsed_type => hash } : hash
|
64
|
-
hash.
|
64
|
+
hash.reverse_merge(@params.except(:data)).deep_symbolize_keys
|
65
65
|
end
|
66
66
|
|
67
67
|
private
|
@@ -35,6 +35,8 @@ module JsonapiCompliable
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def sideload(results, includes)
|
38
|
+
return if results == []
|
39
|
+
|
38
40
|
includes.each_pair do |name, nested|
|
39
41
|
if @resource.allowed_sideloads.has_key?(name)
|
40
42
|
sideload = @resource.sideload(name)
|
@@ -49,7 +51,7 @@ module JsonapiCompliable
|
|
49
51
|
@object = JsonapiCompliable::Scoping::ExtraFields.new(@resource, query_hash, @object).apply unless opts[:extra_fields] == false
|
50
52
|
@object = JsonapiCompliable::Scoping::Sort.new(@resource, query_hash, @object).apply unless opts[:sort] == false
|
51
53
|
@unpaginated_object = @object
|
52
|
-
@object = JsonapiCompliable::Scoping::Paginate.new(@resource, query_hash, @object).apply unless opts[:paginate] == false
|
54
|
+
@object = JsonapiCompliable::Scoping::Paginate.new(@resource, query_hash, @object, default: opts[:default_paginate]).apply unless opts[:paginate] == false
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -3,14 +3,23 @@ module JsonapiCompliable
|
|
3
3
|
class Base
|
4
4
|
attr_reader :resource, :query_hash
|
5
5
|
|
6
|
-
def initialize(resource, query_hash, scope)
|
6
|
+
def initialize(resource, query_hash, scope, opts = {})
|
7
7
|
@query_hash = query_hash
|
8
8
|
@resource = resource
|
9
9
|
@scope = scope
|
10
|
+
@opts = opts
|
10
11
|
end
|
11
12
|
|
12
13
|
def apply
|
13
|
-
|
14
|
+
if apply?
|
15
|
+
apply_standard_or_override
|
16
|
+
else
|
17
|
+
@scope
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def apply?
|
22
|
+
true
|
14
23
|
end
|
15
24
|
|
16
25
|
def apply_standard_or_override
|
@@ -93,7 +93,7 @@ module JsonapiCompliable
|
|
93
93
|
|
94
94
|
def resolve_basic(parents, query, namespace)
|
95
95
|
sideload_scope = scope_proc.call(parents)
|
96
|
-
sideload_scope = Scope.new(sideload_scope, resource_class.new, query, namespace: namespace)
|
96
|
+
sideload_scope = Scope.new(sideload_scope, resource_class.new, query, default_paginate: false, namespace: namespace)
|
97
97
|
sideload_results = sideload_scope.resolve
|
98
98
|
assign_proc.call(parents, sideload_results)
|
99
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_compliable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-03-
|
12
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-serializable
|