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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be276922cefff8fd33e93a926cc1a4bf34121c9749dfe139be50c273bd2394f5
4
- data.tar.gz: d8a30f2fe726f735157480c34ed9735b82acbb62dcd5ec0e32795842d548d740
3
+ metadata.gz: 33d4ea8f4ac1590f792f64a125d1a7005f98720c56d4932f41b6f8493912c548
4
+ data.tar.gz: 569f220a16986e813a89fea0d2b6fd25e99c8b1e1c6874c36f2ca72a5c6a555c
5
5
  SHA512:
6
- metadata.gz: 86be049fae7d2990b93d9e851d0ff719aeb01aef19c708a6ef981ff53390598211a7cd464dd5e00dbf57e502479e3881de13f244b3b4aa2fade0728ff2335f6e
7
- data.tar.gz: e31549972b7c78b82147d56ba983616d33fe8a155e232a87665c328dc55e5fd60cabe13a5b379aa8a4be40dd058145d22246365c18ac6d9b18cdfcbd442d5583
6
+ metadata.gz: b8dfa3e4690f5f3b35833fd7c3fcfbfb762fd6fafe4375804339688e3bd0d451dc19108c8846428b7a4a4b66c965d9635d405dd928742f878c9b00923418967c
7
+ data.tar.gz: 2d11614d1dec4302221b46b27aff89eebb674db1dee4d7feb99abb76e0e36117e6ab195327160e20bafca0d0052ed61e1aa72888ec047409b2f4a169b3b5e2bd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Mobility Ransack Changelog
2
2
 
3
+ ## 1.1
4
+
5
+ ### 1.1.0
6
+ - Make MobilityRansack handle associations correctly
7
+ ([#20](https://github.com/shioyama/mobility-ransack/pull/20))
8
+
3
9
  ## 1.0
4
10
 
5
11
  ### 1.0.1
data/Gemfile.lock CHANGED
@@ -1,135 +1,139 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility-ransack (1.0.0)
5
- mobility (~> 1.0.0)
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.0.3.4)
12
- actionpack (= 6.0.3.4)
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.0.3.4)
16
- actionpack (= 6.0.3.4)
17
- activejob (= 6.0.3.4)
18
- activerecord (= 6.0.3.4)
19
- activestorage (= 6.0.3.4)
20
- activesupport (= 6.0.3.4)
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.0.3.4)
23
- actionpack (= 6.0.3.4)
24
- actionview (= 6.0.3.4)
25
- activejob (= 6.0.3.4)
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.0.3.4)
29
- actionview (= 6.0.3.4)
30
- activesupport (= 6.0.3.4)
31
- rack (~> 2.0, >= 2.0.8)
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.0.3.4)
36
- actionpack (= 6.0.3.4)
37
- activerecord (= 6.0.3.4)
38
- activestorage (= 6.0.3.4)
39
- activesupport (= 6.0.3.4)
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.0.3.4)
42
- activesupport (= 6.0.3.4)
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.0.3.4)
48
- activesupport (= 6.0.3.4)
49
+ activejob (6.1.3.2)
50
+ activesupport (= 6.1.3.2)
49
51
  globalid (>= 0.3.6)
50
- activemodel (6.0.3.4)
51
- activesupport (= 6.0.3.4)
52
- activerecord (6.0.3.4)
53
- activemodel (= 6.0.3.4)
54
- activesupport (= 6.0.3.4)
55
- activestorage (6.0.3.4)
56
- actionpack (= 6.0.3.4)
57
- activejob (= 6.0.3.4)
58
- activerecord (= 6.0.3.4)
59
- marcel (~> 0.3.1)
60
- activesupport (6.0.3.4)
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 (>= 0.7, < 2)
63
- minitest (~> 5.1)
64
- tzinfo (~> 1.1)
65
- zeitwerk (~> 2.2, >= 2.2.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.7)
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.9.0)
77
+ erubi (1.10.0)
74
78
  globalid (0.4.2)
75
79
  activesupport (>= 4.2.0)
76
- i18n (1.8.5)
80
+ i18n (1.8.10)
77
81
  concurrent-ruby (~> 1.0)
78
- loofah (2.7.0)
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.3.3)
84
- mimemagic (~> 0.3.2)
87
+ marcel (1.0.1)
85
88
  method_source (1.0.0)
86
- mimemagic (0.3.5)
87
- mini_mime (1.0.2)
88
- mini_portile2 (2.4.0)
89
- minitest (5.14.2)
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.4)
94
- nokogiri (1.10.10)
95
- mini_portile2 (~> 2.4.0)
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.0.3.4)
106
- actioncable (= 6.0.3.4)
107
- actionmailbox (= 6.0.3.4)
108
- actionmailer (= 6.0.3.4)
109
- actionpack (= 6.0.3.4)
110
- actiontext (= 6.0.3.4)
111
- actionview (= 6.0.3.4)
112
- activejob (= 6.0.3.4)
113
- activemodel (= 6.0.3.4)
114
- activerecord (= 6.0.3.4)
115
- activestorage (= 6.0.3.4)
116
- activesupport (= 6.0.3.4)
117
- bundler (>= 1.3.0)
118
- railties (= 6.0.3.4)
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.0.3.4)
126
- actionpack (= 6.0.3.4)
127
- activesupport (= 6.0.3.4)
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 (>= 0.20.3, < 2.0)
134
+ thor (~> 1.0)
131
135
  rake (13.0.1)
132
- ransack (2.4.0)
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.1)
160
- thread_safe (0.3.6)
161
- tzinfo (1.2.7)
162
- thread_safe (~> 0.1)
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.1)
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.0.0)
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.1'
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Mobility
2
2
  module Ransack
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  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.1
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-03-28 00:00:00.000000000 Z
11
+ date: 2021-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ransack