ransack_predicate_cont_any_word 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +6 -0
- data/Rakefile +1 -0
- data/lib/ransack_predicate_cont_any_word/version.rb +1 -1
- data/lib/ransack_predicate_cont_any_word.rb +36 -2
- data/lib/tasks/release_tasks.rake +88 -0
- metadata +11 -11
- data/lib/tasks/ransack_predicate_cont_any_word_tasks.rake +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d0fc1ff8953bb4d195e40d129267b30ce21f27ef7ba017a72d39fdd8f6a2e8d1
|
|
4
|
+
data.tar.gz: a1c25e479c2047fbb5d0d43c1c73a1c52104a26075375666e21e20f288443500
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4401c31ca5a0a5443408fe00ba6871b342a54321727267f6908fc660bb7ac3b739cc75dca3eacba43c974ac7cae80e47b4da7724fe7e090a46ad0efcb5863419
|
|
7
|
+
data.tar.gz: 132a4e3bb2ad27ac867bd8185bb70361c31a8164d1f84419d7b48b7d235b110e50216b273ca9c876c76ed9e3fee04b84ea968e437e930a9f221319a4962d77fa
|
data/README.md
CHANGED
|
@@ -13,6 +13,12 @@ It is also possible to search for whole sentences
|
|
|
13
13
|
User.ransack(encrypted_password_cont_any_word: '"yeah this is my password" password some').result.to_sql #=> SELECT "users".* FROM "users" WHERE ("users"."encrypted_password" LIKE '%yeah this is my password%' AND "users"."encrypted_password" LIKE '%password%' AND "users"."encrypted_password" LIKE '%some%')
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
For OR-combined attributes, each word may match in different columns:
|
|
17
|
+
```ruby
|
|
18
|
+
User.ransack(email_or_encrypted_password_cont_any_word: "@example.com encrypted_password").result.to_sql
|
|
19
|
+
#=> SELECT "users".* FROM "users" WHERE (("users"."email" LIKE '%@example.com%' OR "users"."encrypted_password" LIKE '%@example.com%') AND ("users"."email" LIKE '%encrypted_password%' OR "users"."encrypted_password" LIKE '%encrypted_password%'))
|
|
20
|
+
```
|
|
21
|
+
|
|
16
22
|
## Installation
|
|
17
23
|
Add this line to your application's Gemfile:
|
|
18
24
|
|
data/Rakefile
CHANGED
|
@@ -3,9 +3,43 @@ module RansackPredicateContAnyWord; end
|
|
|
3
3
|
require "ransack"
|
|
4
4
|
|
|
5
5
|
Ransack.configure do |config|
|
|
6
|
-
config.add_predicate
|
|
6
|
+
config.add_predicate(
|
|
7
|
+
"cont_any_word",
|
|
7
8
|
arel_predicate: "matches_all",
|
|
8
|
-
formatter: proc { |v| v.scan(
|
|
9
|
+
formatter: proc { |v| v.scan(/"(.*?)"|(\S+)/).flatten.compact.map { |t| "%#{t}%" } },
|
|
9
10
|
validator: proc { |v| v.present? },
|
|
10
11
|
type: :string
|
|
12
|
+
)
|
|
11
13
|
end
|
|
14
|
+
|
|
15
|
+
module RansackPredicateContAnyWord::CrossColumnContAnyWordPatch
|
|
16
|
+
def arel_predicate
|
|
17
|
+
return super unless cross_column_cont_any_word?
|
|
18
|
+
|
|
19
|
+
grouped_predicates = cont_any_word_tokens.map do |token|
|
|
20
|
+
attributes
|
|
21
|
+
.map { |attribute| attr_value_for_attribute(attribute).matches(Arel::Nodes.build_quoted(token)) }
|
|
22
|
+
.reduce(:or)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
grouped_predicates.reduce(:and)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def cross_column_cont_any_word?
|
|
31
|
+
predicate_name == "cont_any_word" &&
|
|
32
|
+
combinator == Ransack::Constants::OR &&
|
|
33
|
+
attributes.length > 1 &&
|
|
34
|
+
cont_any_word_tokens.length > 1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def cont_any_word_tokens
|
|
38
|
+
@cont_any_word_tokens ||= validated_values
|
|
39
|
+
.map { |value| value.cast(predicate.type).to_s }
|
|
40
|
+
.flat_map { |value| Array(predicate.format(value)) }
|
|
41
|
+
.compact
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
Ransack::Nodes::Condition.prepend(RansackPredicateContAnyWord::CrossColumnContAnyWordPatch)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require "English"
|
|
2
|
+
require "pty"
|
|
3
|
+
require_relative "../ransack_predicate_cont_any_word/version"
|
|
4
|
+
|
|
5
|
+
task :environment unless Rake::Task.task_defined?(:environment)
|
|
6
|
+
|
|
7
|
+
module ReleaseTasks
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
VERSION_FILE = File.expand_path("../ransack_predicate_cont_any_word/version.rb", __dir__)
|
|
11
|
+
GEMSPEC_FILE = "ransack_predicate_cont_any_word.gemspec".freeze
|
|
12
|
+
|
|
13
|
+
def run_patch_release
|
|
14
|
+
current_version = Gem::Version.new(RansackPredicateContAnyWord::VERSION)
|
|
15
|
+
new_version = next_patch_version(current_version)
|
|
16
|
+
|
|
17
|
+
bump_version!(current_version, new_version)
|
|
18
|
+
build_gem!
|
|
19
|
+
push_gem!(new_version)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def next_patch_version(current_version)
|
|
23
|
+
major, minor, patch = current_version.segments.fill(0, current_version.segments.length...3)
|
|
24
|
+
[major, minor, patch + 1].join(".")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def bump_version!(current_version, new_version)
|
|
28
|
+
version_source = File.read(VERSION_FILE)
|
|
29
|
+
updated_version_source = version_source.sub(
|
|
30
|
+
/VERSION = "[^"]+"\.freeze/,
|
|
31
|
+
"VERSION = \"#{new_version}\".freeze"
|
|
32
|
+
)
|
|
33
|
+
abort "Could not update version in #{VERSION_FILE}" if version_source == updated_version_source
|
|
34
|
+
|
|
35
|
+
File.write(VERSION_FILE, updated_version_source)
|
|
36
|
+
puts "Bumped version: #{current_version} -> #{new_version}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def build_gem!
|
|
40
|
+
abort "gem build failed" unless system("gem", "build", GEMSPEC_FILE)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def push_gem!(new_version)
|
|
44
|
+
gem_file = "ransack_predicate_cont_any_word-#{new_version}.gem"
|
|
45
|
+
abort "Built gem file not found: #{gem_file}" unless File.exist?(gem_file)
|
|
46
|
+
|
|
47
|
+
status = push_gem_via_pty(gem_file)
|
|
48
|
+
abort "gem push failed" unless status&.zero?
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def push_gem_via_pty(gem_file)
|
|
52
|
+
status = nil
|
|
53
|
+
PTY.spawn("gem", "push", gem_file) do |stdout, stdin, pid|
|
|
54
|
+
output_thread = Thread.new { stream_output(stdout) }
|
|
55
|
+
input_thread = Thread.new { stream_input(stdin) }
|
|
56
|
+
|
|
57
|
+
Process.wait(pid)
|
|
58
|
+
status = $CHILD_STATUS.exitstatus
|
|
59
|
+
output_thread.join
|
|
60
|
+
input_thread.kill
|
|
61
|
+
end
|
|
62
|
+
status
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def stream_output(stdout)
|
|
66
|
+
loop do
|
|
67
|
+
print stdout.readpartial(1024)
|
|
68
|
+
end
|
|
69
|
+
rescue EOFError, Errno::EIO => e
|
|
70
|
+
warn e.message if ENV["DEBUG_RELEASE_PATCH"]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def stream_input(stdin)
|
|
74
|
+
loop do
|
|
75
|
+
stdin.write($stdin.readpartial(1024))
|
|
76
|
+
end
|
|
77
|
+
rescue EOFError, Errno::EIO => e
|
|
78
|
+
warn e.message if ENV["DEBUG_RELEASE_PATCH"]
|
|
79
|
+
stdin.close unless stdin.closed?
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
namespace :release do
|
|
84
|
+
desc "Bump patch version, build gem, and push gem to RubyGems"
|
|
85
|
+
task patch: :environment do
|
|
86
|
+
ReleaseTasks.run_patch_release
|
|
87
|
+
end
|
|
88
|
+
end
|
metadata
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ransack_predicate_cont_any_word
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kaspernj
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: "'cont_any_word' predicate for Ransack."
|
|
14
14
|
email:
|
|
15
|
-
-
|
|
15
|
+
- k@spernj.org
|
|
16
16
|
executables: []
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
@@ -22,12 +22,13 @@ files:
|
|
|
22
22
|
- Rakefile
|
|
23
23
|
- lib/ransack_predicate_cont_any_word.rb
|
|
24
24
|
- lib/ransack_predicate_cont_any_word/version.rb
|
|
25
|
-
- lib/tasks/
|
|
25
|
+
- lib/tasks/release_tasks.rake
|
|
26
26
|
homepage: https://www.github.com/kaspernj/ransack_predicate_cont_any_word
|
|
27
27
|
licenses:
|
|
28
28
|
- MIT
|
|
29
|
-
metadata:
|
|
30
|
-
|
|
29
|
+
metadata:
|
|
30
|
+
rubygems_mfa_required: 'true'
|
|
31
|
+
post_install_message:
|
|
31
32
|
rdoc_options: []
|
|
32
33
|
require_paths:
|
|
33
34
|
- lib
|
|
@@ -35,16 +36,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
35
36
|
requirements:
|
|
36
37
|
- - ">="
|
|
37
38
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: '
|
|
39
|
+
version: '2.7'
|
|
39
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
41
|
requirements:
|
|
41
42
|
- - ">="
|
|
42
43
|
- !ruby/object:Gem::Version
|
|
43
44
|
version: '0'
|
|
44
45
|
requirements: []
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
signing_key:
|
|
46
|
+
rubygems_version: 3.5.22
|
|
47
|
+
signing_key:
|
|
48
48
|
specification_version: 4
|
|
49
49
|
summary: "'cont_any_word' predicate for Ransack."
|
|
50
50
|
test_files: []
|