like_query 0.0.14 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/like_query/model_extensions.rb +16 -1
- data/lib/like_query/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbfa734a9e5416b6267b2b9f07f1dbee004c14b77ca11145adfa88a1feae79c3
|
4
|
+
data.tar.gz: 1e7385e5ab95bdead0c203ebb8221faf131bcef925b3d6284a135d3d73a7c29d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e648f6bd86f28d3264299c457139f1760821b9986969be8bf2f552389736f3100ab378a94f3fca4a0f6e6db790add316e68b9e36b26e29cb224a563b6348bf
|
7
|
+
data.tar.gz: 95f6e614d5f227ab29bb35f5f7c765a254432a5ccc0a85b73359f0762d7c96d602080dc4cd3ad42cf9c913dee7744038f1c9d9bab5ff5e1c0e6a08d8e14ec5c8
|
data/README.md
CHANGED
@@ -42,8 +42,9 @@ Article.like('fir', :name, :number)
|
|
42
42
|
# => searches by: "where name like '%fir%' or number like '%fir%'"
|
43
43
|
# => queries are built with Article.arel_table[:name].matches('%fir%')
|
44
44
|
|
45
|
-
Article.like(
|
45
|
+
Article.like('fir ambühl', [:name, :number, customer: :name])
|
46
46
|
# => :customer is the name of the association
|
47
|
+
# => first parameter ('fir ambühl') is equal to ['fir', 'ambühl']
|
47
48
|
# => search-tag as array adds a ".and(where( ... like '%ambühl%'))" for all scoped columns
|
48
49
|
# => would also find art1
|
49
50
|
```
|
@@ -84,6 +85,20 @@ Article.like('fir', :name).generate_hash(:number, limit: 10)
|
|
84
85
|
|
85
86
|
`#generate_hash` uses `LikeQuery::Collect`, functionality is the same.
|
86
87
|
|
88
|
+
**Enums**
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
class Article < ApplicationRecord
|
92
|
+
enum type_enum: { 'Wheel': 0, 'Vehicle': 1, 'Truck': 2 }
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
Article.like('Truck', [:type_enum]).count #=> 1
|
98
|
+
```
|
99
|
+
|
100
|
+
Translated enums and enums on associated models (e.g. article.customer) not yet implemented
|
101
|
+
|
87
102
|
**Class LikeQuery::Collect**
|
88
103
|
|
89
104
|
```ruby
|
@@ -17,7 +17,10 @@ module LikeQuery
|
|
17
17
|
raise "only one array can be given: Either schema as one array or as multiple args, not as array"
|
18
18
|
end
|
19
19
|
(schema.first.is_a?(Array) ? schema.first : schema).each do |p|
|
20
|
-
|
20
|
+
enum_lab = enum_keys(p, s)
|
21
|
+
if enum_lab.present?
|
22
|
+
q = arel_table[p].in(enum_lab)
|
23
|
+
elsif p.is_a?(Symbol) || p.is_a?(String)
|
21
24
|
_q = arel_table[p].matches(str)
|
22
25
|
q = (q ? q.or(_q) : _q)
|
23
26
|
elsif p.is_a?(Hash)
|
@@ -70,5 +73,17 @@ module LikeQuery
|
|
70
73
|
@like_query_schema
|
71
74
|
end
|
72
75
|
|
76
|
+
private
|
77
|
+
|
78
|
+
def enum_keys(column_name, value)
|
79
|
+
en = defined_enums[column_name.to_s]
|
80
|
+
return nil if en.nil?
|
81
|
+
r = []
|
82
|
+
en.each do |k,v|
|
83
|
+
r.push(v) if k.downcase.include?(value.downcase)
|
84
|
+
end
|
85
|
+
r
|
86
|
+
end
|
87
|
+
|
73
88
|
end
|
74
89
|
end
|
data/lib/like_query/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: like_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
63
|
+
rubygems_version: 3.5.3
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: helper for building active record calls.
|