upnxt-ransack 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/initializers/ransack.rb +4 -3
- data/lib/upnxt-ransack.rb +1 -1
- data/lib/upnxt/ransack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd78402254e1cae1f645e68535870c405fae5dc5
|
4
|
+
data.tar.gz: fd990e5a9b7f43590f2631f34b5abb03b9171f4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0515b7b391c36ea1d619e6708036fc9962162040101bd340278231c0ca02befab9d74ff6114b30b0678652cb49382fc441382e6c057720f1ce036c34f37d47f2
|
7
|
+
data.tar.gz: 807b0e5b9edfaad236f354e03b44ea04ce936640e50907c7d292246f99121559a43c6627a3d43525d05dd9fd141908e3c5851761bd1e08895f135347b22130d9
|
@@ -5,14 +5,14 @@ module Ransack
|
|
5
5
|
def initialize(object, params = {}, options = {})
|
6
6
|
params.each do |str, _|
|
7
7
|
str = str.to_s
|
8
|
-
Predicate.detect_and_strip_from_string!(str
|
8
|
+
Predicate.detect_and_strip_from_string!(str)
|
9
9
|
assoc = convert_to_associations(object, str)
|
10
10
|
last = assoc.pop
|
11
11
|
attr_name = last.last
|
12
12
|
prev_class_sym = last.first.name.underscore.to_sym
|
13
13
|
prev_assoc_sym = nil
|
14
14
|
assoc.reverse.each do |klass, str|
|
15
|
-
assoc_sym = str.
|
15
|
+
assoc_sym = str.sub(/_#{attr_name}\z/, '').to_sym
|
16
16
|
klass.has_one(assoc_sym, through: prev_class_sym, source: prev_assoc_sym) unless klass.reflections.keys.include?(assoc_sym)
|
17
17
|
prev_assoc_sym = assoc_sym
|
18
18
|
prev_class_sym = klass.name.underscore.to_sym
|
@@ -24,7 +24,8 @@ module Ransack
|
|
24
24
|
|
25
25
|
private
|
26
26
|
def convert_to_associations(klass, str)
|
27
|
-
|
27
|
+
#sort backwards to favor longer names
|
28
|
+
Hash[klass.reflections.sort{|a,b| b<=>a}].each do |name, reflection|
|
28
29
|
if str.start_with? name.to_s
|
29
30
|
result = convert_to_associations(reflection.class_name.constantize, str.sub("#{name.to_s}_", ''))
|
30
31
|
return [[klass, str]].concat(result) if result
|
data/lib/upnxt-ransack.rb
CHANGED