cancancan-squeel 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/lib/cancancan/squeel/squeel_adapter.rb +28 -16
- data/lib/cancancan/squeel/version.rb +5 -5
- 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: ddabab1d0f04888b81d5c827d646d41536c0f9aa
|
4
|
+
data.tar.gz: b08111a152203b18f750eae54a419e5f3ded83da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3716f52cf0f433d0d22ee33b5404f855553c577de72047809f9bce582eed96ebd22f844584b08f728d8170096503d3434d9af6e452f8daa603ebcf77ccc0e5cc
|
7
|
+
data.tar.gz: 8eceb192ffbf08af18ea5e159476777697ab983428162965a1a388baf045fd253df34b67e57aa7824d413da5b090343753606bb8cafdfde3a55cdf3ad2bf4ef6
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
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
|
-
#
|
86
|
-
|
87
|
-
|
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.
|
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.
|
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-
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|