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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1a466dbd616c05cad9dd31c7c57904056e86e7a
4
- data.tar.gz: ed4007bed09c929be5a54b1e65d8da25721b8b61
3
+ metadata.gz: 51079670b0c1dedbb613140f18d466467aac8176
4
+ data.tar.gz: 25aa3bb0cafd200e8508d7e9492ca6334f2451d4
5
5
  SHA512:
6
- metadata.gz: fd5d8efef4d85afae6f027f89ac1082e28041b6c78cd24a7da33a5e2474132f392b0c97048877fc1ed505ecb943d5a9a587486fc7b87087b34d42a7c9e874f7f
7
- data.tar.gz: 56ceebd8d57413fd798fabe9bb3940f8c73a5bc7c8e3bb9f0d709a77e75f62e261c344a23536c317cd1e214454a1dc5ced7cd55e4829cca9b3d46d315b305e7c
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
- _scope.call.joins(through).where(through => { fk => parents.map { |p| p.send(primary_key) } })
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
- config[:scope].call.where(primary_key => parents.map { |p| p.send(foreign_key) })
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.merge(@params.except(:data)).deep_symbolize_keys
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
- apply_standard_or_override
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
@@ -11,6 +11,14 @@ module JsonapiCompliable
11
11
  end
12
12
  end
13
13
 
14
+ def apply?
15
+ if @opts[:default] == false
16
+ not [page_param[:size], page_param[:number]].all?(&:nil?)
17
+ else
18
+ true
19
+ end
20
+ end
21
+
14
22
  def custom_scope
15
23
  resource.pagination
16
24
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  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.6
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-08 00:00:00.000000000 Z
12
+ date: 2017-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable