cancancan-squeel 0.1.3 → 0.1.4

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: ee0d8f0d270a3449f4c1373eb89857cc047553ea
4
- data.tar.gz: ddc057b7c68e47e087dbed2b707005ccf581b6f7
3
+ metadata.gz: ddabab1d0f04888b81d5c827d646d41536c0f9aa
4
+ data.tar.gz: b08111a152203b18f750eae54a419e5f3ded83da
5
5
  SHA512:
6
- metadata.gz: 0756bbd6699c2eea5eee163425bcc389180028edfcad1b0c839e19bcfea821f0644987083d77069e3235e8db4d103143cb8125d1a5b897a360b669438f89a72d
7
- data.tar.gz: 0db5510c60e8cfe778e6e6cd709ae95fd63ba47467c1b4f0a374561d749fc3a2dcd281530ef5f23020ca604dffaccce0968bc9bda86e7a839f8472fb174fb105
6
+ metadata.gz: 3716f52cf0f433d0d22ee33b5404f855553c577de72047809f9bce582eed96ebd22f844584b08f728d8170096503d3434d9af6e452f8daa603ebcf77ccc0e5cc
7
+ data.tar.gz: 8eceb192ffbf08af18ea5e159476777697ab983428162965a1a388baf045fd253df34b67e57aa7824d413da5b090343753606bb8cafdfde3a55cdf3ad2bf4ef6
@@ -7,7 +7,7 @@ AllCops:
7
7
  - '**/Rakefile'
8
8
  Exclude:
9
9
  - 'vendor/bundle/**/*'
10
- TargetRubyVersion: 2.3
10
+ TargetRubyVersion: 2.1
11
11
 
12
12
  Metrics/LineLength:
13
13
  Max: 100
@@ -1,3 +1,10 @@
1
+ ## master
2
+
3
+ ### bug fixes
4
+
5
+ - Allow querying nested unloaded associations using a database query.
6
+ [@lowjoel](https://github.com/lowjoel)
7
+
1
8
  ## 0.1.3
2
9
 
3
10
  ### enhancements
@@ -52,11 +52,14 @@ class CanCanCan::Squeel::SqueelAdapter < CanCan::ModelAdapters::AbstractAdapter
52
52
  def self.matches_relation?(subject, name, value)
53
53
  relation = subject.public_send(name)
54
54
  klass = subject.class.reflect_on_association(name).klass
55
+ join_list = nil
55
56
 
56
- relation.where do
57
- expression, = CanCanCan::Squeel::ExpressionBuilder.build(self, klass, :==, value)
57
+ scope = relation.where do
58
+ expression, join_list = CanCanCan::Squeel::ExpressionBuilder.build(self, klass, :==, value)
58
59
  expression
59
- end.any?
60
+ end
61
+
62
+ add_joins_to_scope(scope, join_list, :inner).any?
60
63
  end
61
64
  private_class_method :matches_relation?
62
65
 
@@ -65,6 +68,25 @@ class CanCanCan::Squeel::SqueelAdapter < CanCan::ModelAdapters::AbstractAdapter
65
68
  relation.distinct
66
69
  end
67
70
 
71
+ # Builds a relation, outer joined on the provided associations.
72
+ #
73
+ # @param [ActiveRecord::Relation] scope The current scope to add the joins to.
74
+ # @param [Array<Array<Symbol>>] joins The set of associations to outer join with.
75
+ # @param [Symbol] join_type The type of join; defaults to outer joins.
76
+ # @return [ActiveRecord::Relation] The built relation.
77
+ def self.add_joins_to_scope(scope, joins, join_type = :outer)
78
+ joins.reduce(scope) do |result, join|
79
+ result.joins do
80
+ join.reduce(self) do |relation, association|
81
+ relation = relation.__send__(association)
82
+ relation = relation.__send__(join_type) unless join_type == :inner
83
+ relation
84
+ end
85
+ end
86
+ end
87
+ end
88
+ private_class_method :add_joins_to_scope
89
+
68
90
  private
69
91
 
70
92
  # Builds a relation that expresses the set of provided rules.
@@ -82,19 +104,9 @@ class CanCanCan::Squeel::SqueelAdapter < CanCan::ModelAdapters::AbstractAdapter
82
104
  add_joins_to_scope(scope, join_list)
83
105
  end
84
106
 
85
- # Builds a relation, outer joined on the provided associations.
86
- #
87
- # @param [ActiveRecord::Relation] scope The current scope to add the joins to.
88
- # @param [Array<Array<Symbol>>] joins The set of associations to outer join with.
89
- # @return [ActiveRecord::Relation] The built relation.
90
- def add_joins_to_scope(scope, joins)
91
- joins.reduce(scope) do |result, join|
92
- result.joins do
93
- join.reduce(self) do |relation, association|
94
- relation.__send__(association).outer
95
- end
96
- end
97
- end
107
+ # @see CanCanCan::Squeel::SqueelAdapter.add_joins_to_scope
108
+ def add_joins_to_scope(*args)
109
+ self.class.send(:add_joins_to_scope, *args)
98
110
  end
99
111
 
100
112
  # This builds Squeel expression for each rule, and combines the expression with those to the left
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
- module CanCanCan; end
3
- module CanCanCan::Squeel
4
- VERSION = '0.1.3'
5
- end
1
+ # frozen_string_literal: true
2
+ module CanCanCan; end
3
+ module CanCanCan::Squeel
4
+ VERSION = '0.1.4'
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancancan-squeel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Low
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler