like_query 0.0.13 → 0.0.15
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 +18 -1
- data/lib/like_query/extender.rb +7 -0
- data/lib/like_query/model_extensions.rb +16 -1
- data/lib/like_query/railtie.rb +2 -1
- data/lib/like_query/version.rb +1 -1
- data/lib/like_query.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a6b1065f2cdaf7715628fd8034ae6818f2ecd15fe9d5ec96121f92e773382f3b
|
|
4
|
+
data.tar.gz: 28b568fa643003ae89b0f7f77457d0e1ab0f89183f3526104be935b072dd6287
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 427c75b9584a7ab87816641735e3d531f15ec9fceb47655213cdc77d657af983a9741ddc1feb526bb9103168d90a2c92cbabf875a4b122729e4ce2284f99965f
|
|
7
|
+
data.tar.gz: '0282191477287d0a61df3ee2373e4070d866ca5e68801a0880fd446853bd7b9becc3e36b2e2a529c7501486c1138227db8907fbd3aef671ede5bc2e45abff1e4'
|
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
|
|
@@ -206,6 +221,8 @@ Otherwise `#generate_hash` would not know what values to return.
|
|
|
206
221
|
r = c.generate_hash
|
|
207
222
|
```
|
|
208
223
|
|
|
224
|
+
There is a `:no_action` argument on `set_schema`. If set to true, it will return a `no_action: true` on regarding models on the resulting json. This is meant for omitting javascript actions or mouse hover effects for resulting records that should do nothing.
|
|
225
|
+
|
|
209
226
|
**url**
|
|
210
227
|
|
|
211
228
|
You can also use the handy Rails url generators to avoid having to build urls tediously with javascript on the frontend:
|
|
@@ -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
|
|
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/railtie.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module LikeQuery
|
|
2
2
|
class Railtie < Rails::Railtie
|
|
3
3
|
config.after_initialize do
|
|
4
|
-
|
|
4
|
+
#ActiveRecord::Base.send(:extend, LikeQuery::Extender)
|
|
5
|
+
ActiveRecord::Base.send(:extend, LikeQuery::ModelExtensions)
|
|
5
6
|
end
|
|
6
7
|
end
|
|
7
8
|
end
|
data/lib/like_query/version.rb
CHANGED
data/lib/like_query.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.15
|
|
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
|
|
@@ -34,6 +34,7 @@ files:
|
|
|
34
34
|
- README.md
|
|
35
35
|
- lib/like_query.rb
|
|
36
36
|
- lib/like_query/collect.rb
|
|
37
|
+
- lib/like_query/extender.rb
|
|
37
38
|
- lib/like_query/model_extensions.rb
|
|
38
39
|
- lib/like_query/railtie.rb
|
|
39
40
|
- lib/like_query/version.rb
|
|
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
59
60
|
- !ruby/object:Gem::Version
|
|
60
61
|
version: '0'
|
|
61
62
|
requirements: []
|
|
62
|
-
rubygems_version: 3.
|
|
63
|
+
rubygems_version: 3.5.3
|
|
63
64
|
signing_key:
|
|
64
65
|
specification_version: 4
|
|
65
66
|
summary: helper for building active record calls.
|