mobility-ransack 1.0.0 → 1.2.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: 9e2b2fb4a83837ab504f3094122475e7f3dd47370419e475553eb6a50dcd32b6
4
- data.tar.gz: afbe3bacb2c1acbf5d2e83f07c72e03f51ff02aab08b1de8e00f59ecb4ba06b8
3
+ metadata.gz: 1875d7ec16b978a380c59ff6d7422537e860dbe797fb44755d1659b55121c11a
4
+ data.tar.gz: a489d834de55dd89265b787c858d799ba77040e24d929329f0fa4f684f0c4da1
5
5
  SHA512:
6
- metadata.gz: 9746d4b0acf3509a5080bfc091b364cc4774b4e62e2c43824f68c286f5c2d2c3776f31024b5b13d113d2b1324abba4745f5b8cba2bb31d0927f86a572f87582f
7
- data.tar.gz: a17f31df6addb9f42a6c22e0a081746dc9a07d67538596588801bab37d2ce210105921e3193e1019c1b4bbab99d895965e6994d6ee90e1d0c45ddf068a89fc44
6
+ metadata.gz: 4c13a01c141709e58e5061461dad39f4239c3d71e3f15bed3894bb59f11b6b15d1c0423bcd4008f6382abb40200dcf11d2a08d95227c3a5716436e370876180e
7
+ data.tar.gz: 373dbc15c6dd9690b6672c160761dfd91977ebe99808f1457b37c4cae056f19231b3c1e6b5dedd345965591949a1c0ad81cfb9d05570c32d3400d40beb1c05fe
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Mobility Ransack Changelog
2
2
 
3
+ ## 1.1
4
+
5
+ ### 1.2.0
6
+ - [Add compatibility with rails
7
+ 7+](https://github.com/shioyama/mobility-ransack/pull/22), thanks
8
+ [mhenrixon](https://github.com/mhenrixon)!
9
+ - [Update mobility-ransack.gemspec](https://github.com/shioyama/mobility-ransack/pull/23),
10
+ thanks [kevynlebouille](https://github.com/kevynlebouille)!
11
+
12
+ ### 1.1.0
13
+ - Make MobilityRansack handle associations correctly
14
+ ([#20](https://github.com/shioyama/mobility-ransack/pull/20))
15
+
16
+ ## 1.0
17
+
18
+ ### 1.0.1
19
+ - Update gemspec to support Mobility 1.x
20
+ ([#17](https://github.com/shioyama/mobility-ransack/pull/17))
21
+
22
+ ### 1.0.0
23
+ - Enable Mobility 1.x compatibility
24
+ ([#10](https://github.com/shioyama/mobility-ransack/pull/10))
25
+
3
26
  ## 0.2
4
27
 
5
28
  ### 0.2.2
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  group :development, :test do
9
- gem 'rails', "~> #{ENV['RAILS_VERSION'] || '6.0'}"
9
+ gem 'rails', "~> #{ENV['RAILS_VERSION'] || '6.1'}.0"
10
10
 
11
11
  gem 'pry'
12
12
  gem 'pry-byebug'
data/Gemfile.lock CHANGED
@@ -1,135 +1,141 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility-ransack (1.0.0)
5
- mobility (~> 1.0.0)
4
+ mobility-ransack (1.1.0)
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)
99
+ nokogiri (1.11.7-x86_64-linux)
100
+ racc (~> 1.4)
96
101
  pry (0.13.0)
97
102
  coderay (~> 1.1)
98
103
  method_source (~> 1.0)
99
104
  pry-byebug (3.9.0)
100
105
  byebug (~> 11.0)
101
106
  pry (~> 0.13.0)
107
+ racc (1.5.2)
102
108
  rack (2.2.3)
103
109
  rack-test (1.1.0)
104
110
  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)
111
+ rails (6.1.3.2)
112
+ actioncable (= 6.1.3.2)
113
+ actionmailbox (= 6.1.3.2)
114
+ actionmailer (= 6.1.3.2)
115
+ actionpack (= 6.1.3.2)
116
+ actiontext (= 6.1.3.2)
117
+ actionview (= 6.1.3.2)
118
+ activejob (= 6.1.3.2)
119
+ activemodel (= 6.1.3.2)
120
+ activerecord (= 6.1.3.2)
121
+ activestorage (= 6.1.3.2)
122
+ activesupport (= 6.1.3.2)
123
+ bundler (>= 1.15.0)
124
+ railties (= 6.1.3.2)
119
125
  sprockets-rails (>= 2.0.0)
120
126
  rails-dom-testing (2.0.3)
121
127
  activesupport (>= 4.2.0)
122
128
  nokogiri (>= 1.6)
123
129
  rails-html-sanitizer (1.3.0)
124
130
  loofah (~> 2.3)
125
- railties (6.0.3.4)
126
- actionpack (= 6.0.3.4)
127
- activesupport (= 6.0.3.4)
131
+ railties (6.1.3.2)
132
+ actionpack (= 6.1.3.2)
133
+ activesupport (= 6.1.3.2)
128
134
  method_source
129
135
  rake (>= 0.8.7)
130
- thor (>= 0.20.3, < 2.0)
136
+ thor (~> 1.0)
131
137
  rake (13.0.1)
132
- ransack (2.4.0)
138
+ ransack (2.4.2)
133
139
  activerecord (>= 5.2.4)
134
140
  activesupport (>= 5.2.4)
135
141
  i18n
@@ -156,27 +162,28 @@ GEM
156
162
  activesupport (>= 4.0)
157
163
  sprockets (>= 3.0.0)
158
164
  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)
165
+ thor (1.1.0)
166
+ tzinfo (2.0.4)
167
+ concurrent-ruby (~> 1.0)
168
+ websocket-driver (0.7.4)
164
169
  websocket-extensions (>= 0.1.0)
165
170
  websocket-extensions (0.1.5)
166
- zeitwerk (2.4.1)
171
+ zeitwerk (2.4.2)
167
172
 
168
173
  PLATFORMS
169
174
  ruby
175
+ x86_64-linux
170
176
 
171
177
  DEPENDENCIES
172
178
  database_cleaner (~> 1.7, >= 1.7.0)
173
179
  mobility-ransack!
174
180
  pry
175
181
  pry-byebug
176
- rails (~> 6.0)
182
+ rails (~> 6.1.0)
177
183
  rake (>= 12.3.3)
184
+ ransack (= 2.4.2)
178
185
  rspec (~> 3.0)
179
186
  sqlite3 (~> 1.3, >= 1.3.0)
180
187
 
181
188
  BUNDLED WITH
182
- 2.0.2
189
+ 2.2.2
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.0'
21
+ gem 'mobility-ransack', '~> 1.2.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,34 +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.flatten.map(&:name))
39
- end
40
- end
41
-
42
- private
43
-
44
- def apply_mobility_scope(relation, predicate, attributes)
45
- mobility_attributes = attributes.select { |attr| object.mobility_attribute?(attr) }
46
- mobility_attributes.inject(relation) do |i18n_rel, attr|
47
- object.mobility_backend_class(attr).apply_scope(i18n_rel, predicate)
48
- end
49
21
  end
50
22
  end
51
23
  end
@@ -1,5 +1,5 @@
1
1
  module Mobility
2
2
  module Ransack
3
- VERSION = "1.0.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  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
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.0
4
+ version: 1.2.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: 2020-12-17 00:00:00.000000000 Z
11
+ date: 2022-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ransack
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 1.8.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '3.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,21 +29,27 @@ dependencies:
29
29
  version: 1.8.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '3.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: mobility
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 1.0.0
39
+ version: 1.0.1
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
45
48
  - !ruby/object:Gem::Version
46
- version: 1.0.0
49
+ version: 1.0.1
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: rake
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -76,42 +82,42 @@ dependencies:
76
82
  name: sqlite3
77
83
  requirement: !ruby/object:Gem::Requirement
78
84
  requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: 1.3.0
82
85
  - - "~>"
83
86
  - !ruby/object:Gem::Version
84
87
  version: '1.3'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.3.0
85
91
  type: :development
86
92
  prerelease: false
87
93
  version_requirements: !ruby/object:Gem::Requirement
88
94
  requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: 1.3.0
92
95
  - - "~>"
93
96
  - !ruby/object:Gem::Version
94
97
  version: '1.3'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.3.0
95
101
  - !ruby/object:Gem::Dependency
96
102
  name: database_cleaner
97
103
  requirement: !ruby/object:Gem::Requirement
98
104
  requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: 1.7.0
102
105
  - - "~>"
103
106
  - !ruby/object:Gem::Version
104
107
  version: '1.7'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.7.0
105
111
  type: :development
106
112
  prerelease: false
107
113
  version_requirements: !ruby/object:Gem::Requirement
108
114
  requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: 1.7.0
112
115
  - - "~>"
113
116
  - !ruby/object:Gem::Version
114
117
  version: '1.7'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.7.0
115
121
  description:
116
122
  email:
117
123
  - chris@dejimata.com
@@ -147,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
153
  - !ruby/object:Gem::Version
148
154
  version: '0'
149
155
  requirements: []
150
- rubygems_version: 3.0.6
156
+ rubygems_version: 3.1.2
151
157
  signing_key:
152
158
  specification_version: 4
153
159
  summary: Search attributes translated by Mobility with Ransack.