ransacker_translator 0.0.3 → 0.1.2

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
- SHA1:
3
- metadata.gz: 69169d28871dd3550b69d84b51f7077a83a509ae
4
- data.tar.gz: 12462d3bf91a16c78bea987aeb951d914079c9e4
2
+ SHA256:
3
+ metadata.gz: bcd66f080cb541c4f4deddde0b0168e43c632ac7529a4627316b307dce5dbde4
4
+ data.tar.gz: 19b4d1f63e23d63b0fb5932fef02c6f147958a036155d09ac9760f6448e70cdf
5
5
  SHA512:
6
- metadata.gz: 3649f0d5312f66e9583796237b9778f39b1f01fd368373caa1bd8d5ea1dd9ca1b864bb7ac72766f51d2853890dfea24a968fe72836fe7ea92d33de8000883f01
7
- data.tar.gz: cb9bb32fe484d8d7831425d39504883d21a04491b9c6c7025f3e41129ca2ffd77e3adc8cd6d9dc95948f18764ad9050a655ddf718779457e484270b28cb54fe2
6
+ metadata.gz: 43f16bcd68fbc37b149e2f7fb1b54784d9a174679fb6b4f5bddeba29395dfdf8a62ddf6873d15d042008a7ac7d93c16d3312202f1b02924319673cae4e7f79ef
7
+ data.tar.gz: 3a58b4a017b74539a195fd353a5986bf03e63d83f231b48b5afc4885a61709655e28bcfad3027c4da65976642cb128f97107efde29e7e6b457108e5263f7f859
data/Rakefile CHANGED
@@ -1,32 +1,6 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
6
3
 
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
4
+ RSpec::Core::RakeTask.new(:spec)
16
5
 
17
-
18
-
19
-
20
- Bundler::GemHelper.install_tasks
21
-
22
- require 'rake/testtask'
23
-
24
- Rake::TestTask.new(:test) do |t|
25
- t.libs << 'lib'
26
- t.libs << 'test'
27
- t.pattern = 'test/**/*_test.rb'
28
- t.verbose = false
29
- end
30
-
31
-
32
- task default: :test
6
+ task :default => :spec
@@ -1,3 +1,5 @@
1
+ require 'active_support'
2
+
1
3
  module RansackerTranslator
2
4
  module FormatRansackParameters
3
5
  extend ActiveSupport::Concern
@@ -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
- module ClassMethods
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|
@@ -11,7 +17,10 @@ module RansackerTranslator
11
17
  double_byte_char = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !#$%&¥;:'
12
18
  Arel::Nodes::NamedFunction.new("UPPER",
13
19
  [Arel::Nodes::NamedFunction.new("TRANSLATE",
14
- [parent.table[column], double_byte_char, single_byte_char])])
20
+ [parent.table[column],
21
+ double_byte_char,
22
+ single_byte_char].map { |it| Arel::Nodes.build_quoted(it) })
23
+ ])
15
24
  end
16
25
  end
17
26
  end
@@ -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.view_helpers" do
9
- ActionView::Base.send :include, ViewHelpers
7
+ initializer "ransacker_translator" do
8
+ require 'ransacker_translator/view_helpers/action_view'
10
9
  end
11
10
  end
12
11
  end
@@ -1,3 +1,3 @@
1
1
  module RansackerTranslator
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,44 @@
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
+ if params[:q].present? && params[:q][key].present?
11
+ params[:q][key].join(' ')
12
+ else
13
+ ''
14
+ end
15
+ end
16
+
17
+ # ransacker_translatorでOR検索に使うキーを返す
18
+ #
19
+ # @param [Array<String>] *columns カラム名の配列
20
+ # @return [String] ransacker_translatorでOR検索に使うキー
21
+ def ransack_param_translate_normal_or_key(*columns)
22
+ "#{columns.join("_translate_or_")}_translate_cont_any"
23
+ end
24
+
25
+ # ransacker_translatorでAND検索に使うキーを返す
26
+ #
27
+ # @param [Array<String>] *columns カラム名の配列
28
+ # @return [String] ransacker_translatorでAND検索に使うキー
29
+ def ransack_param_translate_normal_and_key(*columns)
30
+ "#{columns.join("_translate_and_")}_translate_cont_any"
31
+ end
32
+
33
+ # ransacker_translatorで除外検索に使うキーを返す
34
+ #
35
+ # @param [Array<String>] *columns カラム名の配列
36
+ # @return [String] ransacker_translatorで除外検索に使うキー
37
+ def ransack_param_translate_ignore_key(*columns)
38
+ "#{columns.join("_translate_and_")}_translate_not_cont_all"
39
+ end
40
+
41
+ ::ActionView::Base.send :include, self
42
+ end
43
+ end
44
+ end
@@ -1 +1,4 @@
1
- require 'ransacker_translator/railtie' if defined? Rails
1
+ require 'ransacker_translator/version'
2
+ require 'ransacker_translator/railtie'
3
+ module RansackerTranslator
4
+ end
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.0.3
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Toyoaki Oko
7
+ - patorash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-26 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 5.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 7.1.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 4.0.0
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
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::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,75 @@ dependencies:
39
105
  - !ruby/object:Gem::Version
40
106
  version: '0'
41
107
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
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: :development
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: rspec
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '3.0'
128
+ type: :development
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '3.0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: pry
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ - !ruby/object:Gem::Dependency
150
+ name: database_cleaner
151
+ requirement: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - "~>"
154
+ - !ruby/object:Gem::Version
155
+ version: '1.7'
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - "~>"
161
+ - !ruby/object:Gem::Version
162
+ version: '1.7'
163
+ - !ruby/object:Gem::Dependency
164
+ name: rspec_junit_formatter
165
+ requirement: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: 0.4.1
170
+ type: :development
171
+ prerelease: false
172
+ version_requirements: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - "~>"
175
+ - !ruby/object:Gem::Version
176
+ version: 0.4.1
55
177
  description: expand search by ransack
56
178
  email:
57
179
  - chariderpato@gmail.com
@@ -66,7 +188,7 @@ files:
66
188
  - lib/ransacker_translator/models/concerns/ransacker_translator.rb
67
189
  - lib/ransacker_translator/railtie.rb
68
190
  - lib/ransacker_translator/version.rb
69
- - lib/ransacker_translator/view_helpers.rb
191
+ - lib/ransacker_translator/view_helpers/action_view.rb
70
192
  homepage: https://github.com/patorash/ransacker_translator
71
193
  licenses:
72
194
  - MIT
@@ -86,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
208
  - !ruby/object:Gem::Version
87
209
  version: '0'
88
210
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.4.3
211
+ rubygems_version: 3.0.3.1
91
212
  signing_key:
92
213
  specification_version: 4
93
214
  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