mobility-ransack 0.1.1 → 0.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: 3e1f7aa59365ce176d9a5baccd87f8091b1d5c23f4532b66c019cf4766b23e43
4
- data.tar.gz: 81b3dc8e4294177dbdad6b2403057adfd41756c103e0e803369e7c4a62884140
3
+ metadata.gz: b666246ec54369683b3ca4c47ab7a37b276b8f6edd105dbfe001438dc8946b63
4
+ data.tar.gz: 2c6bc9c9703f0a1a14f6eea1ca53bd1098b685d4964e8f2ba926ed801e95de67
5
5
  SHA512:
6
- metadata.gz: 6f7daffdd7c1f8bb740628ffdbdfe5f52322705afaf970d56a7a7cd56bd06b14673c4af4897c0080bc6d74867d69b8beb5a1b4cda00051d763b98a04e41bbebf
7
- data.tar.gz: ae9f596d2d64ff45b5f7a3e562c04dd6ee6fc9e593fddd91f92cc1294384a355360d30d6e75089f22d0ee92ce42755c67706d528c57ec971d23f578e0c2e6f25
6
+ metadata.gz: 294f956b8dbbfee07354f44f6fd3a27f58f234d274e7361501adb84472c59918f4e133641d140d1e71f0f20e6584af4b961a649d84523737ed1aa3916ccdc408
7
+ data.tar.gz: 931b32c4430f2623434012710b6436245ddabe1b7522d6b1f703a0038ae7b18d5382daf563a260a77b18d1dbfd3df72d75bd4ea1ae24b0e5a7d737d64eacadf9
@@ -1,5 +1,12 @@
1
1
  # Mobility Ransack Changelog
2
2
 
3
+ ## 0.2
4
+
5
+ ### 0.2.0
6
+
7
+ - Support sorting on translated attributes
8
+ ([#2](https://github.com/shioyama/mobility-ransack/pull/2))
9
+
3
10
  ## 0.1
4
11
 
5
12
  ### 0.1.1
@@ -9,5 +16,7 @@
9
16
  ### 0.1.0
10
17
  - Loosen Ransack dependency to allow up to 2.1
11
18
 
19
+ ## 0.0
20
+
12
21
  ### 0.0.1
13
22
  - Add plugin code.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility-ransack (0.1.0)
4
+ mobility-ransack (0.1.1)
5
5
  mobility (~> 0.8.0)
6
6
  ransack (>= 1.8.0, < 2.1)
7
7
 
@@ -55,6 +55,7 @@ GEM
55
55
  coderay (1.1.2)
56
56
  concurrent-ruby (1.0.5)
57
57
  crass (1.0.4)
58
+ database_cleaner (1.7.0)
58
59
  diff-lcs (1.3)
59
60
  erubi (1.7.1)
60
61
  globalid (0.4.1)
@@ -153,6 +154,7 @@ PLATFORMS
153
154
  ruby
154
155
 
155
156
  DEPENDENCIES
157
+ database_cleaner (~> 1.7.0)
156
158
  mobility-ransack!
157
159
  pry
158
160
  pry-byebug
data/README.md CHANGED
@@ -16,7 +16,7 @@ Search on translated attributes with
16
16
  Just add the gem to your Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'mobility-ransack', '~> 0.1.1'
19
+ gem 'mobility-ransack', '~> 0.2.0'
20
20
  ```
21
21
 
22
22
  Now enable the `ransack` plugin in Mobility's configuration so that it can be
@@ -26,11 +26,20 @@ module Mobility
26
26
 
27
27
  class Search < ::Ransack::Search
28
28
  def result(opts = {})
29
- conditions.inject(super) do |relation, condition|
30
- predicate = condition.arel_predicate
31
- (condition.attributes.compact.flatten.map(&:name) & object.mobility_attributes).inject(relation) do |i18n_rel, attr|
32
- object.mobility_backend_class(attr).apply_scope(i18n_rel, predicate)
33
- end
29
+ sorted = sorts.inject(super) do |relation, sort|
30
+ predicate = ::Ransack::Visitor.new.visit_Ransack_Nodes_Sort(sort)
31
+ apply_mobility_scope(relation, predicate, [sort.attr_name])
32
+ end
33
+ conditions.inject(sorted) do |relation, condition|
34
+ apply_mobility_scope(relation, condition.arel_predicate, condition.attributes.compact.flatten.map(&:name))
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def apply_mobility_scope(relation, predicate, attributes)
41
+ (attributes & object.mobility_attributes).inject(relation) do |i18n_rel, attr|
42
+ object.mobility_backend_class(attr).apply_scope(i18n_rel, predicate)
34
43
  end
35
44
  end
36
45
  end
@@ -1,5 +1,5 @@
1
1
  module Mobility
2
2
  module Ransack
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobility-ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: database_cleaner
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.7.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.7.0
89
103
  description:
90
104
  email:
91
105
  - chris@dejimata.com