kiroshi 0.3.0 → 0.3.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 +4 -4
- data/README.md +3 -3
- data/lib/kiroshi/filter_query/like.rb +5 -9
- data/lib/kiroshi/version.rb +1 -1
- data/spec/lib/kiroshi/filter_query/like_spec.rb +9 -9
- data/spec/lib/kiroshi/filter_runner_spec.rb +2 -2
- data/spec/lib/kiroshi/filters/class_methods_spec.rb +3 -3
- data/spec/lib/kiroshi/filters_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd64f4d8224df2417b3668f60fefdbaf11749f4eeb6bd0381d24d1635d6833c8
|
4
|
+
data.tar.gz: c67d36844e10bcc2121c53cf25ce3fad39e4327e5eb177441c13aed5357cd209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c4086090a07690af87d41507d6e0b8ce64207c46f5301fc6152424cfbfa31894256bacfac8f1405df36915af7da11878b3292f55373e6f7ddc3a32fa021379
|
7
|
+
data.tar.gz: 2c49cf0d1828c65b97c829756adefa4ad4bb5328e1646ef631ef30d9f2005b50a1cce3a765a13af1dfaa0c9ff5dc949283be2a2c5bb9a73fa55bf93696cb88cc
|
data/README.md
CHANGED
@@ -7,16 +7,16 @@
|
|
7
7
|
|
8
8
|
## Yard Documentation
|
9
9
|
|
10
|
-
[https://www.rubydoc.info/gems/kiroshi/0.3.
|
10
|
+
[https://www.rubydoc.info/gems/kiroshi/0.3.1](https://www.rubydoc.info/gems/kiroshi/0.3.1)
|
11
11
|
|
12
12
|
Kiroshi has been designed to make filtering ActiveRecord queries easier
|
13
13
|
by providing a flexible and reusable filtering system. It allows you to
|
14
14
|
define filter sets that can be applied to any ActiveRecord scope,
|
15
15
|
supporting both exact matches and partial matching using SQL LIKE operations.
|
16
16
|
|
17
|
-
Current Release: [0.3.
|
17
|
+
Current Release: [0.3.1](https://github.com/darthjee/kiroshi/tree/0.3.1)
|
18
18
|
|
19
|
-
[Next release](https://github.com/darthjee/kiroshi/compare/0.3.
|
19
|
+
[Next release](https://github.com/darthjee/kiroshi/compare/0.3.1...master)
|
20
20
|
|
21
21
|
## Installation
|
22
22
|
|
@@ -13,7 +13,7 @@ module Kiroshi
|
|
13
13
|
# @example Applying LIKE match query
|
14
14
|
# query = Kiroshi::FilterQuery::Like.new(filter_runner)
|
15
15
|
# query.apply
|
16
|
-
# # Generates: WHERE
|
16
|
+
# # Generates: WHERE `table_name`.`column` LIKE '%value%'
|
17
17
|
#
|
18
18
|
# @since 0.1.1
|
19
19
|
class Like < FilterQuery
|
@@ -28,7 +28,7 @@ module Kiroshi
|
|
28
28
|
# @example Applying LIKE match
|
29
29
|
# query = Like.new(filter_runner)
|
30
30
|
# query.apply
|
31
|
-
# # Generates: WHERE
|
31
|
+
# # Generates: WHERE `documents`.`name` LIKE '%ruby%'
|
32
32
|
#
|
33
33
|
# @since 0.1.1
|
34
34
|
def apply
|
@@ -43,22 +43,18 @@ module Kiroshi
|
|
43
43
|
# Builds the SQL query string for LIKE matching
|
44
44
|
#
|
45
45
|
# This method constructs the SQL fragment with proper table and column
|
46
|
-
# qualification using
|
46
|
+
# qualification using backticks to avoid conflicts with reserved words.
|
47
47
|
#
|
48
48
|
# @return [String] the SQL query fragment for LIKE matching
|
49
49
|
#
|
50
50
|
# @example Generated SQL fragment
|
51
|
-
# sql_query # => ' # Constructs the parameterized SQL query string for column matching
|
52
|
-
#
|
53
|
-
# @return [String] The SQL query string with placeholders
|
54
|
-
# @example
|
55
51
|
# sql_query
|
56
|
-
# # Returns: '
|
52
|
+
# # Returns: '`table_name`.`column` LIKE ?'
|
57
53
|
#
|
58
54
|
# @since 0.3.0
|
59
55
|
def sql_query
|
60
56
|
<<~SQL.squish
|
61
|
-
|
57
|
+
`#{table_name}`.`#{column}` LIKE ?
|
62
58
|
SQL
|
63
59
|
end
|
64
60
|
end
|
data/lib/kiroshi/version.rb
CHANGED
@@ -17,7 +17,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
17
17
|
|
18
18
|
let(:expected_sql) do
|
19
19
|
<<~SQL.squish
|
20
|
-
SELECT "documents".* FROM "documents" WHERE (
|
20
|
+
SELECT "documents".* FROM "documents" WHERE (`documents`.`name` LIKE '%test%')
|
21
21
|
SQL
|
22
22
|
end
|
23
23
|
|
@@ -47,7 +47,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
47
47
|
|
48
48
|
let(:expected_sql) do
|
49
49
|
<<~SQL.squish
|
50
|
-
SELECT "documents".* FROM "documents" WHERE (
|
50
|
+
SELECT "documents".* FROM "documents" WHERE (`documents`.`status` LIKE '%pub%')
|
51
51
|
SQL
|
52
52
|
end
|
53
53
|
|
@@ -78,7 +78,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
78
78
|
|
79
79
|
let(:expected_sql) do
|
80
80
|
<<~SQL.squish
|
81
|
-
SELECT "documents".* FROM "documents" WHERE (
|
81
|
+
SELECT "documents".* FROM "documents" WHERE (`documents`.`version` LIKE '%1.2%')
|
82
82
|
SQL
|
83
83
|
end
|
84
84
|
|
@@ -104,7 +104,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
104
104
|
|
105
105
|
let(:expected_sql) do
|
106
106
|
<<~SQL.squish
|
107
|
-
SELECT "documents".* FROM "documents" WHERE (
|
107
|
+
SELECT "documents".* FROM "documents" WHERE (`documents`.`name` LIKE '%nonexistent%')
|
108
108
|
SQL
|
109
109
|
end
|
110
110
|
|
@@ -218,7 +218,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
218
218
|
|
219
219
|
it 'generates SQL with tags table qualification' do
|
220
220
|
result_sql = query.apply.to_sql
|
221
|
-
expect(result_sql).to include('
|
221
|
+
expect(result_sql).to include('`tags`.`name` LIKE')
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'generates SQL with correct LIKE pattern for tag name' do
|
@@ -245,7 +245,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
245
245
|
|
246
246
|
it 'generates SQL with documents table qualification' do
|
247
247
|
result_sql = query.apply.to_sql
|
248
|
-
expect(result_sql).to include('
|
248
|
+
expect(result_sql).to include('`documents`.`name` LIKE')
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'generates SQL with correct LIKE pattern for document name' do
|
@@ -263,7 +263,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
263
263
|
|
264
264
|
it 'generates SQL with string table qualification' do
|
265
265
|
result_sql = query.apply.to_sql
|
266
|
-
expect(result_sql).to include('
|
266
|
+
expect(result_sql).to include('`tags`.`name` LIKE')
|
267
267
|
end
|
268
268
|
end
|
269
269
|
end
|
@@ -278,7 +278,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
278
278
|
|
279
279
|
let(:expected_sql) do
|
280
280
|
<<~SQL.squish
|
281
|
-
SELECT "documents".* FROM "documents" WHERE (
|
281
|
+
SELECT "documents".* FROM "documents" WHERE (`documents`.`full_name` LIKE '%John%')
|
282
282
|
SQL
|
283
283
|
end
|
284
284
|
|
@@ -303,7 +303,7 @@ RSpec.describe Kiroshi::FilterQuery::Like, type: :model do
|
|
303
303
|
|
304
304
|
let(:expected_sql) do
|
305
305
|
<<~SQL.squish
|
306
|
-
SELECT "documents".* FROM "documents" WHERE (
|
306
|
+
SELECT "documents".* FROM "documents" WHERE (`documents`.`full_name` LIKE '%John%')
|
307
307
|
SQL
|
308
308
|
end
|
309
309
|
|
@@ -39,7 +39,7 @@ RSpec.describe Kiroshi::FilterRunner, type: :model do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'generates correct SQL with table name prefix' do
|
42
|
-
expected_sql = "SELECT \"documents\".* FROM \"documents\" WHERE (
|
42
|
+
expected_sql = "SELECT \"documents\".* FROM \"documents\" WHERE (`documents`.`name` LIKE '%test%')"
|
43
43
|
expect(runner.apply.to_sql).to eq(expected_sql)
|
44
44
|
end
|
45
45
|
end
|
@@ -126,7 +126,7 @@ RSpec.describe Kiroshi::FilterRunner, type: :model do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'generates correct LIKE SQL using the column name' do
|
129
|
-
expected_sql = "SELECT \"documents\".* FROM \"documents\" WHERE (
|
129
|
+
expected_sql = "SELECT \"documents\".* FROM \"documents\" WHERE (`documents`.`full_name` LIKE '%John%')"
|
130
130
|
expect(runner.apply.to_sql).to eq(expected_sql)
|
131
131
|
end
|
132
132
|
end
|
@@ -52,7 +52,7 @@ RSpec.describe Kiroshi::Filters::ClassMethods, type: :model do
|
|
52
52
|
it do
|
53
53
|
expect { filters_class.filter_by :name, match: :like, table: :documents }
|
54
54
|
.to change { filter_instance.apply(scope) }
|
55
|
-
.from(scope).to(scope.where('
|
55
|
+
.from(scope).to(scope.where('`documents`.`name` LIKE ?', '%test%'))
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -73,7 +73,7 @@ RSpec.describe Kiroshi::Filters::ClassMethods, type: :model do
|
|
73
73
|
it do
|
74
74
|
expect { filters_class.filter_by :user_name, match: :like, column: :full_name }
|
75
75
|
.to change { filter_instance.apply(scope) }
|
76
|
-
.from(scope).to(scope.where('
|
76
|
+
.from(scope).to(scope.where('`documents`.`full_name` LIKE ?', '%John%'))
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -95,7 +95,7 @@ RSpec.describe Kiroshi::Filters::ClassMethods, type: :model do
|
|
95
95
|
it do
|
96
96
|
expect { filters_class.filter_by :tag_identifier, match: :like, table: :tags, column: :name }
|
97
97
|
.to change { filter_instance.apply(scope) }
|
98
|
-
.from(scope).to(scope.where('
|
98
|
+
.from(scope).to(scope.where('`tags`.`name` LIKE ?', '%rub%'))
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -279,7 +279,7 @@ RSpec.describe Kiroshi::Filters, type: :model do
|
|
279
279
|
|
280
280
|
it 'generates SQL with table-qualified LIKE operation' do
|
281
281
|
result = filter_instance.apply(scope)
|
282
|
-
expect(result.to_sql).to include('
|
282
|
+
expect(result.to_sql).to include('`documents`.`name` LIKE')
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'generates SQL with correct LIKE pattern' do
|
@@ -336,7 +336,7 @@ RSpec.describe Kiroshi::Filters, type: :model do
|
|
336
336
|
end
|
337
337
|
|
338
338
|
it 'generates SQL with LIKE operation on the specified column' do
|
339
|
-
expect(filter_instance.apply(scope).to_sql).to include('
|
339
|
+
expect(filter_instance.apply(scope).to_sql).to include('`tags`.`name` LIKE')
|
340
340
|
end
|
341
341
|
|
342
342
|
it 'generates SQL with correct LIKE pattern' do
|
@@ -353,7 +353,7 @@ RSpec.describe Kiroshi::Filters, type: :model do
|
|
353
353
|
|
354
354
|
it 'uses the column name in database queries' do
|
355
355
|
result = filter_instance.apply(Document.all)
|
356
|
-
expect(result.to_sql).to include('
|
356
|
+
expect(result.to_sql).to include('`documents`.`name`')
|
357
357
|
end
|
358
358
|
|
359
359
|
it 'does not use the filter key in SQL' do
|
@@ -451,7 +451,7 @@ RSpec.describe Kiroshi::Filters, type: :model do
|
|
451
451
|
end
|
452
452
|
|
453
453
|
it 'generates SQL that does not include documents.name' do
|
454
|
-
expect(filter_instance.apply(scope).to_sql).not_to include('
|
454
|
+
expect(filter_instance.apply(scope).to_sql).not_to include('`documents`.`name`')
|
455
455
|
end
|
456
456
|
|
457
457
|
it 'generates SQL that includes the tag filter value' do
|