mobility-ransack 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +85 -82
- data/README.md +1 -4
- data/lib/mobility/plugins/ransack.rb +0 -27
- data/lib/mobility/ransack.rb +50 -0
- data/lib/mobility/ransack/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33d4ea8f4ac1590f792f64a125d1a7005f98720c56d4932f41b6f8493912c548
|
4
|
+
data.tar.gz: 569f220a16986e813a89fea0d2b6fd25e99c8b1e1c6874c36f2ca72a5c6a555c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8dfa3e4690f5f3b35833fd7c3fcfbfb762fd6fafe4375804339688e3bd0d451dc19108c8846428b7a4a4b66c965d9635d405dd928742f878c9b00923418967c
|
7
|
+
data.tar.gz: 2d11614d1dec4302221b46b27aff89eebb674db1dee4d7feb99abb76e0e36117e6ab195327160e20bafca0d0052ed61e1aa72888ec047409b2f4a169b3b5e2bd
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,135 +1,139 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mobility-ransack (1.0.
|
5
|
-
mobility (
|
4
|
+
mobility-ransack (1.0.1)
|
5
|
+
mobility (>= 1.0.1, < 2.0)
|
6
6
|
ransack (>= 1.8.0, < 3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (6.
|
12
|
-
actionpack (= 6.
|
11
|
+
actioncable (6.1.3.2)
|
12
|
+
actionpack (= 6.1.3.2)
|
13
|
+
activesupport (= 6.1.3.2)
|
13
14
|
nio4r (~> 2.0)
|
14
15
|
websocket-driver (>= 0.6.1)
|
15
|
-
actionmailbox (6.
|
16
|
-
actionpack (= 6.
|
17
|
-
activejob (= 6.
|
18
|
-
activerecord (= 6.
|
19
|
-
activestorage (= 6.
|
20
|
-
activesupport (= 6.
|
16
|
+
actionmailbox (6.1.3.2)
|
17
|
+
actionpack (= 6.1.3.2)
|
18
|
+
activejob (= 6.1.3.2)
|
19
|
+
activerecord (= 6.1.3.2)
|
20
|
+
activestorage (= 6.1.3.2)
|
21
|
+
activesupport (= 6.1.3.2)
|
21
22
|
mail (>= 2.7.1)
|
22
|
-
actionmailer (6.
|
23
|
-
actionpack (= 6.
|
24
|
-
actionview (= 6.
|
25
|
-
activejob (= 6.
|
23
|
+
actionmailer (6.1.3.2)
|
24
|
+
actionpack (= 6.1.3.2)
|
25
|
+
actionview (= 6.1.3.2)
|
26
|
+
activejob (= 6.1.3.2)
|
27
|
+
activesupport (= 6.1.3.2)
|
26
28
|
mail (~> 2.5, >= 2.5.4)
|
27
29
|
rails-dom-testing (~> 2.0)
|
28
|
-
actionpack (6.
|
29
|
-
actionview (= 6.
|
30
|
-
activesupport (= 6.
|
31
|
-
rack (~> 2.0, >= 2.0.
|
30
|
+
actionpack (6.1.3.2)
|
31
|
+
actionview (= 6.1.3.2)
|
32
|
+
activesupport (= 6.1.3.2)
|
33
|
+
rack (~> 2.0, >= 2.0.9)
|
32
34
|
rack-test (>= 0.6.3)
|
33
35
|
rails-dom-testing (~> 2.0)
|
34
36
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
-
actiontext (6.
|
36
|
-
actionpack (= 6.
|
37
|
-
activerecord (= 6.
|
38
|
-
activestorage (= 6.
|
39
|
-
activesupport (= 6.
|
37
|
+
actiontext (6.1.3.2)
|
38
|
+
actionpack (= 6.1.3.2)
|
39
|
+
activerecord (= 6.1.3.2)
|
40
|
+
activestorage (= 6.1.3.2)
|
41
|
+
activesupport (= 6.1.3.2)
|
40
42
|
nokogiri (>= 1.8.5)
|
41
|
-
actionview (6.
|
42
|
-
activesupport (= 6.
|
43
|
+
actionview (6.1.3.2)
|
44
|
+
activesupport (= 6.1.3.2)
|
43
45
|
builder (~> 3.1)
|
44
46
|
erubi (~> 1.4)
|
45
47
|
rails-dom-testing (~> 2.0)
|
46
48
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
-
activejob (6.
|
48
|
-
activesupport (= 6.
|
49
|
+
activejob (6.1.3.2)
|
50
|
+
activesupport (= 6.1.3.2)
|
49
51
|
globalid (>= 0.3.6)
|
50
|
-
activemodel (6.
|
51
|
-
activesupport (= 6.
|
52
|
-
activerecord (6.
|
53
|
-
activemodel (= 6.
|
54
|
-
activesupport (= 6.
|
55
|
-
activestorage (6.
|
56
|
-
actionpack (= 6.
|
57
|
-
activejob (= 6.
|
58
|
-
activerecord (= 6.
|
59
|
-
|
60
|
-
|
52
|
+
activemodel (6.1.3.2)
|
53
|
+
activesupport (= 6.1.3.2)
|
54
|
+
activerecord (6.1.3.2)
|
55
|
+
activemodel (= 6.1.3.2)
|
56
|
+
activesupport (= 6.1.3.2)
|
57
|
+
activestorage (6.1.3.2)
|
58
|
+
actionpack (= 6.1.3.2)
|
59
|
+
activejob (= 6.1.3.2)
|
60
|
+
activerecord (= 6.1.3.2)
|
61
|
+
activesupport (= 6.1.3.2)
|
62
|
+
marcel (~> 1.0.0)
|
63
|
+
mini_mime (~> 1.0.2)
|
64
|
+
activesupport (6.1.3.2)
|
61
65
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
62
|
-
i18n (>=
|
63
|
-
minitest (
|
64
|
-
tzinfo (~>
|
65
|
-
zeitwerk (~> 2.
|
66
|
+
i18n (>= 1.6, < 2)
|
67
|
+
minitest (>= 5.1)
|
68
|
+
tzinfo (~> 2.0)
|
69
|
+
zeitwerk (~> 2.3)
|
66
70
|
builder (3.2.4)
|
67
71
|
byebug (11.1.1)
|
68
72
|
coderay (1.1.2)
|
69
|
-
concurrent-ruby (1.1.
|
73
|
+
concurrent-ruby (1.1.9)
|
70
74
|
crass (1.0.6)
|
71
75
|
database_cleaner (1.8.4)
|
72
76
|
diff-lcs (1.3)
|
73
|
-
erubi (1.
|
77
|
+
erubi (1.10.0)
|
74
78
|
globalid (0.4.2)
|
75
79
|
activesupport (>= 4.2.0)
|
76
|
-
i18n (1.8.
|
80
|
+
i18n (1.8.10)
|
77
81
|
concurrent-ruby (~> 1.0)
|
78
|
-
loofah (2.
|
82
|
+
loofah (2.10.0)
|
79
83
|
crass (~> 1.0.2)
|
80
84
|
nokogiri (>= 1.5.9)
|
81
85
|
mail (2.7.1)
|
82
86
|
mini_mime (>= 0.1.1)
|
83
|
-
marcel (0.
|
84
|
-
mimemagic (~> 0.3.2)
|
87
|
+
marcel (1.0.1)
|
85
88
|
method_source (1.0.0)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
mobility (1.0.0)
|
89
|
+
mini_mime (1.0.3)
|
90
|
+
mini_portile2 (2.5.3)
|
91
|
+
minitest (5.14.4)
|
92
|
+
mobility (1.1.2)
|
91
93
|
i18n (>= 0.6.10, < 2)
|
92
94
|
request_store (~> 1.0)
|
93
|
-
nio4r (2.5.
|
94
|
-
nokogiri (1.
|
95
|
-
mini_portile2 (~> 2.
|
95
|
+
nio4r (2.5.7)
|
96
|
+
nokogiri (1.11.7)
|
97
|
+
mini_portile2 (~> 2.5.0)
|
98
|
+
racc (~> 1.4)
|
96
99
|
pry (0.13.0)
|
97
100
|
coderay (~> 1.1)
|
98
101
|
method_source (~> 1.0)
|
99
102
|
pry-byebug (3.9.0)
|
100
103
|
byebug (~> 11.0)
|
101
104
|
pry (~> 0.13.0)
|
105
|
+
racc (1.5.2)
|
102
106
|
rack (2.2.3)
|
103
107
|
rack-test (1.1.0)
|
104
108
|
rack (>= 1.0, < 3)
|
105
|
-
rails (6.
|
106
|
-
actioncable (= 6.
|
107
|
-
actionmailbox (= 6.
|
108
|
-
actionmailer (= 6.
|
109
|
-
actionpack (= 6.
|
110
|
-
actiontext (= 6.
|
111
|
-
actionview (= 6.
|
112
|
-
activejob (= 6.
|
113
|
-
activemodel (= 6.
|
114
|
-
activerecord (= 6.
|
115
|
-
activestorage (= 6.
|
116
|
-
activesupport (= 6.
|
117
|
-
bundler (>= 1.
|
118
|
-
railties (= 6.
|
109
|
+
rails (6.1.3.2)
|
110
|
+
actioncable (= 6.1.3.2)
|
111
|
+
actionmailbox (= 6.1.3.2)
|
112
|
+
actionmailer (= 6.1.3.2)
|
113
|
+
actionpack (= 6.1.3.2)
|
114
|
+
actiontext (= 6.1.3.2)
|
115
|
+
actionview (= 6.1.3.2)
|
116
|
+
activejob (= 6.1.3.2)
|
117
|
+
activemodel (= 6.1.3.2)
|
118
|
+
activerecord (= 6.1.3.2)
|
119
|
+
activestorage (= 6.1.3.2)
|
120
|
+
activesupport (= 6.1.3.2)
|
121
|
+
bundler (>= 1.15.0)
|
122
|
+
railties (= 6.1.3.2)
|
119
123
|
sprockets-rails (>= 2.0.0)
|
120
124
|
rails-dom-testing (2.0.3)
|
121
125
|
activesupport (>= 4.2.0)
|
122
126
|
nokogiri (>= 1.6)
|
123
127
|
rails-html-sanitizer (1.3.0)
|
124
128
|
loofah (~> 2.3)
|
125
|
-
railties (6.
|
126
|
-
actionpack (= 6.
|
127
|
-
activesupport (= 6.
|
129
|
+
railties (6.1.3.2)
|
130
|
+
actionpack (= 6.1.3.2)
|
131
|
+
activesupport (= 6.1.3.2)
|
128
132
|
method_source
|
129
133
|
rake (>= 0.8.7)
|
130
|
-
thor (
|
134
|
+
thor (~> 1.0)
|
131
135
|
rake (13.0.1)
|
132
|
-
ransack (2.4.
|
136
|
+
ransack (2.4.1)
|
133
137
|
activerecord (>= 5.2.4)
|
134
138
|
activesupport (>= 5.2.4)
|
135
139
|
i18n
|
@@ -156,14 +160,13 @@ GEM
|
|
156
160
|
activesupport (>= 4.0)
|
157
161
|
sprockets (>= 3.0.0)
|
158
162
|
sqlite3 (1.4.2)
|
159
|
-
thor (1.0
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
websocket-driver (0.7.3)
|
163
|
+
thor (1.1.0)
|
164
|
+
tzinfo (2.0.4)
|
165
|
+
concurrent-ruby (~> 1.0)
|
166
|
+
websocket-driver (0.7.4)
|
164
167
|
websocket-extensions (>= 0.1.0)
|
165
168
|
websocket-extensions (0.1.5)
|
166
|
-
zeitwerk (2.4.
|
169
|
+
zeitwerk (2.4.2)
|
167
170
|
|
168
171
|
PLATFORMS
|
169
172
|
ruby
|
@@ -173,7 +176,7 @@ DEPENDENCIES
|
|
173
176
|
mobility-ransack!
|
174
177
|
pry
|
175
178
|
pry-byebug
|
176
|
-
rails (~> 6.
|
179
|
+
rails (~> 6.1.0)
|
177
180
|
rake (>= 12.3.3)
|
178
181
|
rspec (~> 3.0)
|
179
182
|
sqlite3 (~> 1.3, >= 1.3.0)
|
data/README.md
CHANGED
@@ -18,12 +18,9 @@ Search on translated attributes with
|
|
18
18
|
Just add the gem to your Gemfile:
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem 'mobility-ransack', '~> 1.0
|
21
|
+
gem 'mobility-ransack', '~> 1.1.0'
|
22
22
|
```
|
23
23
|
|
24
|
-
(For Mobility versions earlier than 1.0, replace `1.0.0` with `0.2.2`, but be
|
25
|
-
aware this version is no longer supported.)
|
26
|
-
|
27
24
|
Now enable the `ransack` plugin in Mobility's configuration:
|
28
25
|
|
29
26
|
```ruby
|
@@ -18,33 +18,6 @@ module Mobility
|
|
18
18
|
names.each do |name|
|
19
19
|
klass.ransacker(name) { backend_class.build_node(name, Mobility.locale) }
|
20
20
|
end
|
21
|
-
klass.extend ClassMethods
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
def ransack(*)
|
27
|
-
super.extend(Search)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
module Search
|
32
|
-
def result(opts = {})
|
33
|
-
sorted = sorts.inject(super) do |relation, sort|
|
34
|
-
predicate = ::Ransack::Visitor.new.visit_Ransack_Nodes_Sort(sort)
|
35
|
-
apply_mobility_scope(relation, predicate, [sort.attr_name])
|
36
|
-
end
|
37
|
-
conditions.inject(sorted) do |relation, condition|
|
38
|
-
apply_mobility_scope(relation, condition.arel_predicate, condition.attributes.compact.flat_map(&:name))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def apply_mobility_scope(relation, predicate, attributes)
|
45
|
-
(attributes & object.mobility_attributes).inject(relation) do |i18n_rel, attr|
|
46
|
-
object.mobility_backend_class(attr).apply_scope(i18n_rel, predicate)
|
47
|
-
end
|
48
21
|
end
|
49
22
|
end
|
50
23
|
end
|
data/lib/mobility/ransack.rb
CHANGED
@@ -1,6 +1,56 @@
|
|
1
1
|
require "mobility/ransack/version"
|
2
|
+
require "mobility/plugins/arel"
|
3
|
+
require "ransack"
|
2
4
|
|
3
5
|
module Mobility
|
4
6
|
module Ransack
|
7
|
+
class Visitor < Mobility::Plugins::Arel::Visitor
|
8
|
+
def initialize
|
9
|
+
super(nil, nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def visit_collection(objects)
|
15
|
+
objects.map(&method(:visit)).sum.uniq
|
16
|
+
end
|
17
|
+
alias :visit_Array :visit_collection
|
18
|
+
alias :visit_Arel_Nodes_Equality :visit_Arel_Nodes_Binary
|
19
|
+
alias :visit_Arel_Nodes_Or :visit_Arel_Nodes_Binary
|
20
|
+
|
21
|
+
def visit_Mobility_Plugins_Arel_Attribute(object)
|
22
|
+
[[object.backend_class, object.locale]]
|
23
|
+
end
|
24
|
+
|
25
|
+
def visit_default(_)
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Search
|
31
|
+
def result(opts = {})
|
32
|
+
sorted = sorts.inject(super) do |relation, sort|
|
33
|
+
predicate = ::Ransack::Visitor.new.visit_Ransack_Nodes_Sort(sort)
|
34
|
+
apply_mobility_scope(relation, predicate, [sort.attr_name])
|
35
|
+
end
|
36
|
+
conditions.inject(sorted) do |relation, condition|
|
37
|
+
apply_mobility_scope(relation, condition.arel_predicate, condition.attributes.compact.flat_map(&:name))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def apply_mobility_scope(relation, predicate, attributes)
|
44
|
+
visitor.accept(predicate).inject(relation) do |i18n_rel, (backend_class, locale)|
|
45
|
+
backend_class.apply_scope(i18n_rel, predicate, locale)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def visitor
|
50
|
+
@visitor ||= Visitor.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
::Ransack::Search.prepend Search
|
5
55
|
end
|
6
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobility-ransack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ransack
|