ransacker_translator 0.0.4 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +9 -29
- data/lib/ransacker_translator/controllers/concerns/format_ransack_parameters.rb +8 -6
- data/lib/ransacker_translator/models/concerns/ransacker_translator.rb +7 -1
- data/lib/ransacker_translator/railtie.rb +2 -3
- data/lib/ransacker_translator/version.rb +1 -1
- data/lib/ransacker_translator/view_helpers/action_view.rb +40 -0
- data/lib/ransacker_translator.rb +4 -1
- metadata +105 -12
- data/lib/ransacker_translator/view_helpers.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8633aee62921eee8dca30c1ffb78be7283e1c348727d0398041c51918b5281c3
|
4
|
+
data.tar.gz: 2eda830220d76a5cfeb063fb4636807564b7a39b24fd001201cb725c2b056f26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424c6b78251e4dc7136cc3957639a023bd0f0ca1ba15720604eaa5c73a0f1c6b677360f21c888d11baaa167ea93653305e0c8ba77d480707c0a755d3dd159c67
|
7
|
+
data.tar.gz: e90f11fda5259f4997bf40343001f1996945e2c607cc6056e8d90d138fd56107d8008228705d9a97738fb5f4d3c00a9f5f222d069ca0729f87ac3a5c01001956
|
data/Rakefile
CHANGED
@@ -1,32 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
# require 'rdoc/task'
|
8
|
-
#
|
9
|
-
# RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
# rdoc.rdoc_dir = 'rdoc'
|
11
|
-
# rdoc.title = 'RansackerTranslator'
|
12
|
-
# rdoc.options << '--line-numbers'
|
13
|
-
# rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
# end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Bundler::GemHelper.install_tasks
|
21
|
-
|
1
|
+
require "bundler/gem_tasks"
|
22
2
|
require 'rake/testtask'
|
23
3
|
|
24
|
-
|
25
|
-
t.libs << 'lib'
|
26
|
-
t.libs << 'test'
|
27
|
-
t.pattern = 'test/**/*_test.rb'
|
28
|
-
t.verbose = false
|
29
|
-
end
|
4
|
+
task :default => [:test]
|
30
5
|
|
31
|
-
|
32
|
-
|
6
|
+
Rake::TestTask.new do |test|
|
7
|
+
test.libs << 'lib'
|
8
|
+
test.libs << 'test'
|
9
|
+
test.test_files = Dir['test/**/*_test.rb']
|
10
|
+
test.warning = false
|
11
|
+
# test.verbose = true
|
12
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
1
3
|
module RansackerTranslator
|
2
4
|
module FormatRansackParameters
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
private
|
8
|
+
|
9
|
+
def format_ransack_params
|
10
|
+
params[:q]&.keys.each do |key|
|
11
|
+
if key.end_with?('_all', '_any') && params.dig(:q, key).instance_of?(String)
|
12
|
+
params[:q][key] = params.dig(:q, key).split(' ')
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
13
|
-
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'nkf'
|
2
|
+
require 'active_support'
|
2
3
|
|
3
4
|
module RansackerTranslator
|
4
5
|
extend ActiveSupport::Concern
|
5
6
|
|
6
|
-
|
7
|
+
class_methods do
|
8
|
+
|
9
|
+
# 指定したカラムでPostgreSQLのTRANSLATE関数を用いて変換をかけた上で検索を行う設定を行う
|
10
|
+
#
|
11
|
+
# @param [Array<Symbol>] *columns カラム名の配列
|
12
|
+
# @return [Void]
|
7
13
|
def ransacker_translate(*columns)
|
8
14
|
columns.each do |column|
|
9
15
|
ransacker :"#{column}_translate", formatter: proc {|v| NKF.nkf('-w -XZ0', v.mb_chars) } do |parent|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'rails/railtie'
|
2
2
|
require 'ransacker_translator/models/concerns/ransacker_translator'
|
3
3
|
require 'ransacker_translator/controllers/concerns/format_ransack_parameters'
|
4
|
-
require 'ransacker_translator/view_helpers'
|
5
4
|
|
6
5
|
module RansackerTranslator
|
7
6
|
class Railtie < ::Rails::Railtie
|
8
|
-
initializer "ransacker_translator
|
9
|
-
|
7
|
+
initializer "ransacker_translator" do
|
8
|
+
require 'ransacker_translator/view_helpers/action_view'
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RansackerTranslator
|
2
|
+
module ViewHelpers
|
3
|
+
module ActionView
|
4
|
+
|
5
|
+
# paramsの指定したkeyの要素を半角スペースで繋いだ文字列にする
|
6
|
+
#
|
7
|
+
# @param [Symbol] key ransackで使っているキー
|
8
|
+
# @return [String] params[:q][key]を半角スペースでつなげた文字列
|
9
|
+
def ransack_params_array_to_s(key)
|
10
|
+
params.dig(:q, key)&.join(' ') || ''
|
11
|
+
end
|
12
|
+
|
13
|
+
# ransacker_translatorでOR検索に使うキーを返す
|
14
|
+
#
|
15
|
+
# @param [Array<String>] *columns カラム名の配列
|
16
|
+
# @return [String] ransacker_translatorでOR検索に使うキー
|
17
|
+
def ransack_param_translate_normal_or_key(*columns)
|
18
|
+
"#{columns.join("_translate_or_")}_translate_cont_any"
|
19
|
+
end
|
20
|
+
|
21
|
+
# ransacker_translatorでAND検索に使うキーを返す
|
22
|
+
#
|
23
|
+
# @param [Array<String>] *columns カラム名の配列
|
24
|
+
# @return [String] ransacker_translatorでAND検索に使うキー
|
25
|
+
def ransack_param_translate_normal_and_key(*columns)
|
26
|
+
"#{columns.join("_translate_and_")}_translate_cont_any"
|
27
|
+
end
|
28
|
+
|
29
|
+
# ransacker_translatorで除外検索に使うキーを返す
|
30
|
+
#
|
31
|
+
# @param [Array<String>] *columns カラム名の配列
|
32
|
+
# @return [String] ransacker_translatorで除外検索に使うキー
|
33
|
+
def ransack_param_translate_ignore_key(*columns)
|
34
|
+
"#{columns.join("_translate_and_")}_translate_not_cont_all"
|
35
|
+
end
|
36
|
+
|
37
|
+
::ActionView::Base.send :include, self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/ransacker_translator.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransacker_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- patorash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 7.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 7.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 5.0.0
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 7.1.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 5.0.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 7.1.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: actionview
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 5.0.0
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 7.1.0
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 5.0.0
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 7.1.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: railties
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 5.0.0
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 7.1.0
|
20
83
|
type: :runtime
|
21
84
|
prerelease: false
|
22
85
|
version_requirements: !ruby/object:Gem::Requirement
|
23
86
|
requirements:
|
24
87
|
- - ">="
|
25
88
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
89
|
+
version: 5.0.0
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 7.1.0
|
27
93
|
- !ruby/object:Gem::Dependency
|
28
94
|
name: ransack
|
29
95
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,19 +105,47 @@ dependencies:
|
|
39
105
|
- !ruby/object:Gem::Version
|
40
106
|
version: '0'
|
41
107
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
108
|
+
name: pg
|
43
109
|
requirement: !ruby/object:Gem::Requirement
|
44
110
|
requirements:
|
45
111
|
- - ">="
|
46
112
|
- !ruby/object:Gem::Version
|
47
113
|
version: '0'
|
48
|
-
type: :
|
114
|
+
type: :runtime
|
49
115
|
prerelease: false
|
50
116
|
version_requirements: !ruby/object:Gem::Requirement
|
51
117
|
requirements:
|
52
118
|
- - ">="
|
53
119
|
- !ruby/object:Gem::Version
|
54
120
|
version: '0'
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: pry
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0.14'
|
128
|
+
type: :development
|
129
|
+
prerelease: false
|
130
|
+
version_requirements: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - "~>"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0.14'
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: database_cleaner
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '1.7'
|
142
|
+
type: :development
|
143
|
+
prerelease: false
|
144
|
+
version_requirements: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - "~>"
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '1.7'
|
55
149
|
description: expand search by ransack
|
56
150
|
email:
|
57
151
|
- chariderpato@gmail.com
|
@@ -66,7 +160,7 @@ files:
|
|
66
160
|
- lib/ransacker_translator/models/concerns/ransacker_translator.rb
|
67
161
|
- lib/ransacker_translator/railtie.rb
|
68
162
|
- lib/ransacker_translator/version.rb
|
69
|
-
- lib/ransacker_translator/view_helpers.rb
|
163
|
+
- lib/ransacker_translator/view_helpers/action_view.rb
|
70
164
|
homepage: https://github.com/patorash/ransacker_translator
|
71
165
|
licenses:
|
72
166
|
- MIT
|
@@ -79,15 +173,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
173
|
requirements:
|
80
174
|
- - ">="
|
81
175
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
176
|
+
version: 2.6.0
|
83
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
178
|
requirements:
|
85
179
|
- - ">="
|
86
180
|
- !ruby/object:Gem::Version
|
87
181
|
version: '0'
|
88
182
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.4.3
|
183
|
+
rubygems_version: 3.0.3.1
|
91
184
|
signing_key:
|
92
185
|
specification_version: 4
|
93
186
|
summary: expand search by ransack
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module RansackerTranslator
|
2
|
-
module ViewHelpers
|
3
|
-
def ransack_params_array_to_s(key)
|
4
|
-
if params[:q].present? && params[:q][key].present?
|
5
|
-
params[:q][key].join(' ')
|
6
|
-
else
|
7
|
-
''
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def ransack_param_translate_normal_or_key(*columns)
|
12
|
-
"#{columns.join("_translate_or_")}_translate_cont_any"
|
13
|
-
end
|
14
|
-
|
15
|
-
def ransack_param_translate_normal_and_key(*columns)
|
16
|
-
"#{columns.join("_translate_and_")}_translate_cont_any"
|
17
|
-
end
|
18
|
-
|
19
|
-
def ransack_param_translate_ignore_key(*columns)
|
20
|
-
"#{columns.join("_translate_and_")}_translate_not_cont_all"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|