ransack 1.8.6 → 1.8.7
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/.travis.yml +18 -0
- data/Gemfile +3 -0
- data/lib/ransack.rb +1 -1
- data/lib/ransack/adapters/active_record/context.rb +42 -23
- data/lib/ransack/adapters/active_record/ransack/constants.rb +1 -1
- data/lib/ransack/adapters/active_record/ransack/context.rb +3 -1
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +2 -2
- data/lib/ransack/constants.rb +1 -0
- data/lib/ransack/helpers/form_builder.rb +10 -4
- data/lib/ransack/nodes/attribute.rb +1 -1
- data/lib/ransack/nodes/grouping.rb +0 -1
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a68f79e9c101613e0af4423267942f4d38007d19
|
4
|
+
data.tar.gz: ae51bdebc41d71f0902c29aeafd570e8057ad59b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39361cd28cb1002386b506a28c4a4065448bb82c23bb3d989c7038ffa33dba628d170f8a2daca58ed3665707de833fe9f8d325884be8a1812dbc07c6e7abce8a
|
7
|
+
data.tar.gz: 1d71cb39bd5524cb9c53313cbd6abf971f248b0c5978b376d3049bfb5ab684e7b6937c7785d0033ba534c52e700559c1c3faa093f368952743e5dd7d41db4f87
|
data/.travis.yml
CHANGED
@@ -9,6 +9,10 @@ rvm:
|
|
9
9
|
- 2.0
|
10
10
|
|
11
11
|
env:
|
12
|
+
- RAILS=5-2-stable DB=sqlite3
|
13
|
+
- RAILS=5-2-stable DB=mysql
|
14
|
+
- RAILS=5-2-stable DB=postgres
|
15
|
+
|
12
16
|
- RAILS=5-0-stable DB=sqlite3
|
13
17
|
- RAILS=5-0-stable DB=mysql
|
14
18
|
- RAILS=5-0-stable DB=postgres
|
@@ -35,6 +39,13 @@ env:
|
|
35
39
|
|
36
40
|
matrix:
|
37
41
|
exclude:
|
42
|
+
- rvm: 2.1.10
|
43
|
+
env: RAILS=5-2-stable DB=sqlite3
|
44
|
+
- rvm: 2.1.10
|
45
|
+
env: RAILS=5-2-stable DB=mysql
|
46
|
+
- rvm: 2.1.10
|
47
|
+
env: RAILS=5-2-stable DB=postgres
|
48
|
+
|
38
49
|
- rvm: 2.1.10
|
39
50
|
env: RAILS=5-0-stable DB=sqlite3
|
40
51
|
- rvm: 2.1.10
|
@@ -42,6 +53,13 @@ matrix:
|
|
42
53
|
- rvm: 2.1.10
|
43
54
|
env: RAILS=5-0-stable DB=postgres
|
44
55
|
|
56
|
+
- rvm: 2.0
|
57
|
+
env: RAILS=5-2-stable DB=sqlite3
|
58
|
+
- rvm: 2.0
|
59
|
+
env: RAILS=5-2-stable DB=mysql
|
60
|
+
- rvm: 2.0
|
61
|
+
env: RAILS=5-2-stable DB=postgres
|
62
|
+
|
45
63
|
- rvm: 2.0
|
46
64
|
env: RAILS=5-0-stable DB=sqlite3
|
47
65
|
- rvm: 2.0
|
data/Gemfile
CHANGED
data/lib/ransack.rb
CHANGED
@@ -14,7 +14,9 @@ module Ransack
|
|
14
14
|
|
15
15
|
def initialize(object, options = {})
|
16
16
|
super
|
17
|
-
|
17
|
+
if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
|
18
|
+
@arel_visitor = @engine.connection.visitor
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def relation_for(object)
|
@@ -25,7 +27,7 @@ module Ransack
|
|
25
27
|
return nil unless attr && attr.valid?
|
26
28
|
name = attr.arel_attribute.name.to_s
|
27
29
|
table = attr.arel_attribute.relation.table_name
|
28
|
-
schema_cache =
|
30
|
+
schema_cache = ::ActiveRecord::Base.connection.schema_cache
|
29
31
|
unless schema_cache.send(database_table_exists?, table)
|
30
32
|
raise "No table named #{table} exists."
|
31
33
|
end
|
@@ -135,7 +137,7 @@ module Ransack
|
|
135
137
|
end
|
136
138
|
|
137
139
|
def alias_tracker
|
138
|
-
@join_dependency.alias_tracker
|
140
|
+
@join_dependency.send(:alias_tracker)
|
139
141
|
end
|
140
142
|
|
141
143
|
def lock_association(association)
|
@@ -145,11 +147,11 @@ module Ransack
|
|
145
147
|
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
|
146
148
|
def remove_association(association)
|
147
149
|
return if @lock_associations.include?(association)
|
148
|
-
@join_dependency.join_root.children.delete_if { |stashed|
|
150
|
+
@join_dependency.instance_variable_get(:@join_root).children.delete_if { |stashed|
|
149
151
|
stashed.eql?(association)
|
150
152
|
}
|
151
153
|
@object.joins_values.delete_if { |jd|
|
152
|
-
jd.join_root.children.map(&:object_id) == [association.object_id]
|
154
|
+
jd.instance_variable_get(:@join_root).children.map(&:object_id) == [association.object_id]
|
153
155
|
}
|
154
156
|
end
|
155
157
|
else
|
@@ -181,7 +183,6 @@ module Ransack
|
|
181
183
|
def build_correlated_subquery(association)
|
182
184
|
join_constraints = extract_joins(association)
|
183
185
|
join_root = join_constraints.shift
|
184
|
-
join_table = join_root.left
|
185
186
|
correlated_key = join_root.right.expr.left
|
186
187
|
subquery = Arel::SelectManager.new(association.base_klass)
|
187
188
|
subquery.from(join_root.left)
|
@@ -280,12 +281,17 @@ module Ransack
|
|
280
281
|
relation.table.from(relation.table), string_joins
|
281
282
|
end
|
282
283
|
|
283
|
-
|
284
|
-
relation.klass, association_joins, join_list
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
284
|
+
if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
|
285
|
+
join_dependency = JoinDependency.new(relation.klass, association_joins, join_list)
|
286
|
+
join_nodes.each do |join|
|
287
|
+
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
288
|
+
end
|
289
|
+
else
|
290
|
+
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, relation.table.name, join_list)
|
291
|
+
join_dependency = JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
|
292
|
+
join_nodes.each do |join|
|
293
|
+
join_dependency.alias_tracker.aliases[join.left.name.downcase] = 1
|
294
|
+
end
|
289
295
|
end
|
290
296
|
|
291
297
|
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
|
@@ -308,7 +314,7 @@ module Ransack
|
|
308
314
|
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
|
309
315
|
|
310
316
|
def find_association(name, parent = @base, klass = nil)
|
311
|
-
@join_dependency.join_root.children.detect do |assoc|
|
317
|
+
@join_dependency.instance_variable_get(:@join_root).children.detect do |assoc|
|
312
318
|
assoc.reflection.name == name &&
|
313
319
|
(@associations_pot.empty? || @associations_pot[assoc] == parent) &&
|
314
320
|
(!klass || assoc.reflection.klass == klass)
|
@@ -316,21 +322,34 @@ module Ransack
|
|
316
322
|
end
|
317
323
|
|
318
324
|
def build_association(name, parent = @base, klass = nil)
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
+
if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
|
326
|
+
jd = JoinDependency.new(
|
327
|
+
parent.base_klass,
|
328
|
+
Polyamorous::Join.new(name, @join_type, klass),
|
329
|
+
[]
|
330
|
+
)
|
331
|
+
found_association = jd.join_root.children.last
|
332
|
+
else
|
333
|
+
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, parent.table.name, [])
|
334
|
+
jd = JoinDependency.new(
|
335
|
+
parent.base_klass,
|
336
|
+
parent.base_klass.arel_table,
|
337
|
+
Polyamorous::Join.new(name, @join_type, klass),
|
338
|
+
alias_tracker
|
339
|
+
)
|
340
|
+
found_association = jd.instance_variable_get(:@join_root).children.last
|
341
|
+
end
|
342
|
+
|
343
|
+
|
325
344
|
@associations_pot[found_association] = parent
|
326
345
|
|
327
346
|
# TODO maybe we dont need to push associations here, we could loop
|
328
347
|
# through the @associations_pot instead
|
329
|
-
@join_dependency.join_root.children.push found_association
|
348
|
+
@join_dependency.instance_variable_get(:@join_root).children.push found_association
|
330
349
|
|
331
350
|
# Builds the arel nodes properly for this association
|
332
351
|
@join_dependency.send(
|
333
|
-
:construct_tables!, jd.join_root, found_association
|
352
|
+
:construct_tables!, jd.instance_variable_get(:@join_root), found_association
|
334
353
|
)
|
335
354
|
|
336
355
|
# Leverage the stashed association functionality in AR
|
@@ -340,7 +359,7 @@ module Ransack
|
|
340
359
|
end
|
341
360
|
|
342
361
|
def extract_joins(association)
|
343
|
-
parent = @join_dependency.join_root
|
362
|
+
parent = @join_dependency.instance_variable_get(:@join_root)
|
344
363
|
reflection = association.reflection
|
345
364
|
join_constraints = if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_1
|
346
365
|
association.join_constraints(
|
@@ -385,7 +404,7 @@ module Ransack
|
|
385
404
|
end
|
386
405
|
|
387
406
|
def find_association(name, parent = @base, klass = nil)
|
388
|
-
|
407
|
+
@join_dependency.join_associations
|
389
408
|
.detect do |assoc|
|
390
409
|
assoc.reflection.name == name &&
|
391
410
|
assoc.parent == parent &&
|
@@ -104,7 +104,7 @@ module Ransack
|
|
104
104
|
case ActiveRecord::Base.connection.adapter_name
|
105
105
|
when "Mysql2".freeze, "PostgreSQL".freeze
|
106
106
|
# Necessary for PostgreSQL and MySQL
|
107
|
-
unescaped.to_s.gsub(/([
|
107
|
+
unescaped.to_s.gsub(/([\\%_.])/, '\\\\\\1')
|
108
108
|
else
|
109
109
|
unescaped
|
110
110
|
end
|
@@ -30,7 +30,9 @@ module Ransack
|
|
30
30
|
@associations_pot = {}
|
31
31
|
@lock_associations = []
|
32
32
|
|
33
|
-
if ::ActiveRecord::VERSION::STRING >= Constants::
|
33
|
+
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_5_2
|
34
|
+
@base = @join_dependency.instance_variable_get(:@join_root)
|
35
|
+
elsif ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
|
34
36
|
@base = @join_dependency.join_root
|
35
37
|
@engine = @base.base_klass.arel_engine
|
36
38
|
else
|
@@ -33,8 +33,8 @@ module Ransack
|
|
33
33
|
predicate = attribute.attr.public_send(arel_pred, arel_values)
|
34
34
|
|
35
35
|
if in_predicate?(predicate)
|
36
|
-
predicate.right = predicate.right.map do |
|
37
|
-
casted_array?(
|
36
|
+
predicate.right = predicate.right.map do |pr|
|
37
|
+
casted_array?(pr) ? format_values_for(pr) : pr
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
data/lib/ransack/constants.rb
CHANGED
@@ -6,9 +6,15 @@ module ActionView::Helpers::Tags
|
|
6
6
|
# https://github.com/rails/rails/commit/c1a118a
|
7
7
|
class Base
|
8
8
|
private
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if ::ActiveRecord::VERSION::STRING < '5.2'
|
10
|
+
def value(object)
|
11
|
+
object.send @method_name if object # use send instead of public_send
|
12
|
+
end
|
13
|
+
else # rails/rails#29791
|
14
|
+
def value
|
15
|
+
@object.send @method_name if @object
|
16
|
+
end
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
@@ -237,7 +243,7 @@ module Ransack
|
|
237
243
|
Translate.association(base, :context => object.context),
|
238
244
|
collection_for_base(action, base)
|
239
245
|
]
|
240
|
-
rescue UntraversableAssociationError
|
246
|
+
rescue UntraversableAssociationError
|
241
247
|
nil
|
242
248
|
end
|
243
249
|
end
|
data/lib/ransack/version.rb
CHANGED
data/ransack.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency 'machinist', '~> 1.0.6'
|
26
26
|
s.add_development_dependency 'faker', '~> 0.9.5'
|
27
27
|
s.add_development_dependency 'sqlite3', '~> 1.3.3'
|
28
|
-
s.add_development_dependency 'pg'
|
28
|
+
s.add_development_dependency 'pg', '~> 0.21'
|
29
29
|
s.add_development_dependency 'mysql2', '0.3.20'
|
30
30
|
s.add_development_dependency 'pry', '0.10'
|
31
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-
|
14
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: actionpack
|
@@ -143,16 +143,16 @@ dependencies:
|
|
143
143
|
name: pg
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
|
-
- - "
|
146
|
+
- - "~>"
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version: '0'
|
148
|
+
version: '0.21'
|
149
149
|
type: :development
|
150
150
|
prerelease: false
|
151
151
|
version_requirements: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
|
-
- - "
|
153
|
+
- - "~>"
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version: '0'
|
155
|
+
version: '0.21'
|
156
156
|
- !ruby/object:Gem::Dependency
|
157
157
|
name: mysql2
|
158
158
|
requirement: !ruby/object:Gem::Requirement
|