segugio 0.1.1 → 0.1.2
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/.ci.database.yml +9 -0
- data/Gemfile +9 -4
- data/Gemfile.lock +39 -13
- data/lib/segugio/search.rb +8 -6
- data/lib/segugio/version.rb +1 -1
- data/lib/segugio/wrappers/active_record/base.rb +2 -0
- metadata +17 -9
- data/sig/segugio.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9713c2995c3372521c1ce92a3423697a502040bfb9b59eac27764da5429c36f
|
4
|
+
data.tar.gz: faabfc804ba1716489d3c05682410fe4c17e4ae77e103c3e08065db092b0d2b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4e40a80b422a75ffc093199522bc138f8141ebdcb2d5b5ac8752db51de607dc00aa61e01556b68b84c73eb37900413ae97c94b76adbf0beffefb712dfdc0fc6
|
7
|
+
data.tar.gz: 9bad96136056c2de795496ebaba25a24e4ab757e0d9035e63607a2dfa150ccf22d6f5b9beed3dfea0bd01dc3e8c6d8eeb376af8a0d9d64b348bba6866ff2d565
|
data/.ci.database.yml
ADDED
data/Gemfile
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in segugio.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
9
|
-
|
10
|
-
gem
|
8
|
+
gem 'database_cleaner'
|
9
|
+
gem 'factory_bot'
|
10
|
+
gem 'faker'
|
11
|
+
gem 'pg'
|
12
|
+
gem 'pry'
|
13
|
+
gem 'rake'
|
14
|
+
gem 'rspec'
|
15
|
+
gem 'shoulda-matchers'
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
segugio (0.1.
|
5
|
-
activerecord (
|
4
|
+
segugio (0.1.2)
|
5
|
+
activerecord (>= 4.0)
|
6
|
+
service-utils (~> 0.2)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
activemodel (7.0.4)
|
11
|
-
activesupport (= 7.0.4)
|
12
|
-
activerecord (7.0.4)
|
13
|
-
activemodel (= 7.0.4)
|
14
|
-
activesupport (= 7.0.4)
|
15
|
-
activesupport (7.0.4)
|
11
|
+
activemodel (7.0.4.1)
|
12
|
+
activesupport (= 7.0.4.1)
|
13
|
+
activerecord (7.0.4.1)
|
14
|
+
activemodel (= 7.0.4.1)
|
15
|
+
activesupport (= 7.0.4.1)
|
16
|
+
activesupport (7.0.4.1)
|
16
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
18
|
i18n (>= 1.6, < 2)
|
18
19
|
minitest (>= 5.1)
|
19
20
|
tzinfo (~> 2.0)
|
21
|
+
coderay (1.1.3)
|
20
22
|
concurrent-ruby (1.1.10)
|
23
|
+
database_cleaner (2.0.1)
|
24
|
+
database_cleaner-active_record (~> 2.0.0)
|
25
|
+
database_cleaner-active_record (2.0.1)
|
26
|
+
activerecord (>= 5.a)
|
27
|
+
database_cleaner-core (~> 2.0.0)
|
28
|
+
database_cleaner-core (2.0.1)
|
21
29
|
diff-lcs (1.5.0)
|
30
|
+
factory_bot (6.2.1)
|
31
|
+
activesupport (>= 5.0.0)
|
32
|
+
faker (3.1.0)
|
33
|
+
i18n (>= 1.8.11, < 2)
|
22
34
|
i18n (1.12.0)
|
23
35
|
concurrent-ruby (~> 1.0)
|
36
|
+
method_source (1.0.0)
|
24
37
|
minitest (5.17.0)
|
38
|
+
pg (1.4.5)
|
39
|
+
pry (0.14.2)
|
40
|
+
coderay (~> 1.1)
|
41
|
+
method_source (~> 1.0)
|
25
42
|
rake (13.0.6)
|
26
43
|
rspec (3.12.0)
|
27
44
|
rspec-core (~> 3.12.0)
|
@@ -29,13 +46,16 @@ GEM
|
|
29
46
|
rspec-mocks (~> 3.12.0)
|
30
47
|
rspec-core (3.12.0)
|
31
48
|
rspec-support (~> 3.12.0)
|
32
|
-
rspec-expectations (3.12.
|
49
|
+
rspec-expectations (3.12.2)
|
33
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
51
|
rspec-support (~> 3.12.0)
|
35
|
-
rspec-mocks (3.12.
|
52
|
+
rspec-mocks (3.12.3)
|
36
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
54
|
rspec-support (~> 3.12.0)
|
38
55
|
rspec-support (3.12.0)
|
56
|
+
service-utils (0.2.0)
|
57
|
+
shoulda-matchers (5.3.0)
|
58
|
+
activesupport (>= 5.2.0)
|
39
59
|
tzinfo (2.0.5)
|
40
60
|
concurrent-ruby (~> 1.0)
|
41
61
|
|
@@ -44,9 +64,15 @@ PLATFORMS
|
|
44
64
|
|
45
65
|
DEPENDENCIES
|
46
66
|
bundler (~> 2.0)
|
47
|
-
|
48
|
-
|
67
|
+
database_cleaner
|
68
|
+
factory_bot
|
69
|
+
faker
|
70
|
+
pg
|
71
|
+
pry
|
72
|
+
rake
|
73
|
+
rspec
|
49
74
|
segugio!
|
75
|
+
shoulda-matchers
|
50
76
|
|
51
77
|
BUNDLED WITH
|
52
|
-
2.3.
|
78
|
+
2.3.6
|
data/lib/segugio/search.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'service/utils'
|
4
|
+
|
3
5
|
module Segugio
|
4
6
|
# Implements a feature for generic search, that allows to search using ILIKE operator, filter records by exact value
|
5
7
|
# and specify result order.
|
@@ -25,7 +27,7 @@ module Segugio
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def logger
|
28
|
-
@logger ||=
|
30
|
+
@logger ||= ActiveRecord::Base.logger
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
@@ -71,7 +73,7 @@ module Segugio
|
|
71
73
|
|
72
74
|
# Generate an array with conditions (ex. ['name ILIKE ? OR title ILIKE ?', '%xyz%', '%xyz%'])
|
73
75
|
conditions = []
|
74
|
-
conditions << @query_fields.map { |field| "#{
|
76
|
+
conditions << @query_fields.map { |field| %("#{collection_name}"."#{field}"::text ILIKE ?) }.join(' OR ')
|
75
77
|
@query_fields.each do
|
76
78
|
conditions << "%#{@query}%"
|
77
79
|
end
|
@@ -85,7 +87,7 @@ module Segugio
|
|
85
87
|
# Iterate over @filter_fields and set filter conditions on result
|
86
88
|
@filter_fields.each do |column|
|
87
89
|
# TODO: handle filters on array columns
|
88
|
-
@result = @result.where(
|
90
|
+
@result = @result.where(collection_name => { column => @filters[column] }) if @filters[column]
|
89
91
|
end
|
90
92
|
|
91
93
|
# Warn about invalid filter fields
|
@@ -97,7 +99,7 @@ module Segugio
|
|
97
99
|
def apply_exclude!
|
98
100
|
# Iterate over @filter_fields and set exclude conditions on result
|
99
101
|
@filter_fields.each do |column|
|
100
|
-
@result = @result.where.not(
|
102
|
+
@result = @result.where.not(collection_name => { column => @exclude[column] }) if @exclude[column]
|
101
103
|
end
|
102
104
|
|
103
105
|
# Warn about invalid exclude fields
|
@@ -120,7 +122,7 @@ module Segugio
|
|
120
122
|
# When order item is a String or a Symbol, just check
|
121
123
|
# if it's valid and use that value as order field
|
122
124
|
if @order_fields.include?(item.to_s)
|
123
|
-
result << "#{
|
125
|
+
result << %("#{collection_name}"."#{item}" ASC)
|
124
126
|
else
|
125
127
|
# Report invalid order item
|
126
128
|
logger.warn "Invalid order item: #{item.inspect}"
|
@@ -146,7 +148,7 @@ module Segugio
|
|
146
148
|
# Build order field from a hash like { field: 'name', asc: true|false|nil, nulls_first: true|false|nil }
|
147
149
|
def build_order_field_from_hash(data)
|
148
150
|
# Use field name as base for order field
|
149
|
-
field = "#{
|
151
|
+
field = %("#{collection_name}"."#{data[:field]}")
|
150
152
|
|
151
153
|
if data.key?(:asc)
|
152
154
|
# When :asc is specified, add "ASC" or "DESC" when its value is "true" or "false" respectively
|
data/lib/segugio/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: segugio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Groza Sergiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,9 +28,6 @@ dependencies:
|
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '7'
|
34
31
|
- - ">="
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '4.0'
|
@@ -38,12 +35,23 @@ dependencies:
|
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '7'
|
44
38
|
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: service-utils
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.2'
|
47
55
|
description: |
|
48
56
|
Segugio is a Ruby gem that simplifies the implementation of search functionality in Rails using ActiveRecord.
|
49
57
|
With this gem, you can easily search, filter and sort results in a simple and intuitive way.
|
@@ -61,6 +69,7 @@ executables: []
|
|
61
69
|
extensions: []
|
62
70
|
extra_rdoc_files: []
|
63
71
|
files:
|
72
|
+
- ".ci.database.yml"
|
64
73
|
- ".rspec"
|
65
74
|
- ".rubocop.yml"
|
66
75
|
- CHANGELOG.md
|
@@ -75,7 +84,6 @@ files:
|
|
75
84
|
- lib/segugio/searchable.rb
|
76
85
|
- lib/segugio/version.rb
|
77
86
|
- lib/segugio/wrappers/active_record/base.rb
|
78
|
-
- sig/segugio.rbs
|
79
87
|
homepage: https://github.com/demetra-it/segugio
|
80
88
|
licenses:
|
81
89
|
- MIT
|
data/sig/segugio.rbs
DELETED