like_query 0.0.11 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/lib/like_query/collect.rb +10 -3
- data/lib/like_query/model_extensions.rb +2 -1
- data/lib/like_query/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88909f6d5d1906a27c6cb848f7fad43a711666bae3f21a4241da60f26a73041a
|
4
|
+
data.tar.gz: f88b8e02d010380d4f71ce258b32991340240402ed666dc269a1e6bfc0c02083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350cccf97727f54769ba1bf732cd5205d8aa98e0601507da50d2c242bf88713c158eecc4353552c9aff3803713c2816c36c7c58f3997fd1c6f9948a2ce5a7eaf
|
7
|
+
data.tar.gz: c6e242f576685d7233ad85a3f3e5633414dac3d56dfdf292c4d938b51ca4e8c8828ec23d01d1c97f411ae99c47c1dfa1a980caef2ee513893114220da6807421
|
data/README.md
CHANGED
@@ -206,6 +206,45 @@ Otherwise `#generate_hash` would not know what values to return.
|
|
206
206
|
r = c.generate_hash
|
207
207
|
```
|
208
208
|
|
209
|
+
**url**
|
210
|
+
|
211
|
+
You can also use the handy Rails url generators to avoid having to build urls tediously with javascript on the frontend:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
customer = Customer.create(name: 'Ambühl')
|
215
|
+
proc1 = proc {|cust| customer_path(cust)}
|
216
|
+
r = Customer.like('ambühl', :name).generate_hash(:name, url: proc1)
|
217
|
+
r[:data].first[:url] #=> "/customer/#{customer.id}"
|
218
|
+
```
|
219
|
+
or
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
customer = Customer.create(name: 'Ambühl')
|
223
|
+
c = LikeQuery::Collect.new
|
224
|
+
proc1 = proc {|cust| customer_path(cust)}
|
225
|
+
c.collect(url: proc1) { Customer.like('ambühl', :name) }
|
226
|
+
r = c.generate_hash
|
227
|
+
r[:data].first[:url] #=> "/customer/#{customer.id}"
|
228
|
+
```
|
229
|
+
|
230
|
+
or
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
customer = Customer.create(name: 'Ambühl')
|
234
|
+
art = Article.create(number: 'art-no', customer: customer)
|
235
|
+
c = LikeQuery::Collect.new
|
236
|
+
proc1 = proc {|cust| customer_path(cust)}
|
237
|
+
|
238
|
+
c.collect(url: proc1) { Customer.like('xyxyxyyxy', :number) }
|
239
|
+
# remember url although nothing found
|
240
|
+
|
241
|
+
proc2 = proc {|article| customer_article_path(article.customer, article) }
|
242
|
+
c.collect(parent: :customer, url: proc2) { Article.like('art', :number) }
|
243
|
+
r = c.generate_hash
|
244
|
+
r[:data].first[:url] #=> "/customer/#{customer.id}"
|
245
|
+
r[:data].first[:children].first[:url] #=> "/customer/#{customer.id}/article/#{art.id}"
|
246
|
+
```
|
247
|
+
|
209
248
|
**Performance**
|
210
249
|
|
211
250
|
Values defined by the schema are processed by the `#send` method, but recursively.
|
data/lib/like_query/collect.rb
CHANGED
@@ -14,16 +14,17 @@ module LikeQuery
|
|
14
14
|
@columns_count = 0
|
15
15
|
@sub_records_columns_count = 0
|
16
16
|
@image = false
|
17
|
-
#@sub_records_image = false
|
18
17
|
@start_time = Time.now
|
19
18
|
@schemes = {}
|
20
19
|
@images = {}
|
21
20
|
@urls = {}
|
21
|
+
@no_action = {}
|
22
22
|
end
|
23
23
|
|
24
|
-
def set_schema(model, schema = nil, url: nil)
|
24
|
+
def set_schema(model, schema = nil, url: nil, no_action: false)
|
25
25
|
@schemes[model.to_s] = schema_to_hash(schema)
|
26
26
|
@urls[model.to_s] = url if url
|
27
|
+
@no_action[model.to_s] = no_action
|
27
28
|
end
|
28
29
|
|
29
30
|
def collect(output_schema = nil, limit: nil, parent: nil, image: nil, url: nil, &block)
|
@@ -40,13 +41,18 @@ module LikeQuery
|
|
40
41
|
end
|
41
42
|
model_name = recs.klass.to_s
|
42
43
|
schema = @schemes[model_name] || schema_to_hash(nil)
|
43
|
-
|
44
|
+
|
44
45
|
_img = image || schema[:image]
|
45
46
|
if _img.present?
|
46
47
|
@images[model_name] = _img
|
47
48
|
@image = true
|
48
49
|
end
|
49
50
|
|
51
|
+
_url = url || @urls[model_name]
|
52
|
+
if url.present?
|
53
|
+
@urls[model_name] = url
|
54
|
+
end
|
55
|
+
|
50
56
|
if parent
|
51
57
|
parent_assoc = recs.klass.reflect_on_association(parent)
|
52
58
|
if !parent_assoc
|
@@ -130,6 +136,7 @@ module LikeQuery
|
|
130
136
|
end
|
131
137
|
r[:image] = record.send(image) if image
|
132
138
|
r[:url] = url.yield(record) if url
|
139
|
+
r[:no_action] = true if @no_action[record.class.to_s]
|
133
140
|
r
|
134
141
|
end
|
135
142
|
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module LikeQuery
|
2
2
|
module ModelExtensions
|
3
3
|
|
4
|
-
def like(search_string,
|
4
|
+
def like(search_string, schema = nil)
|
5
5
|
|
6
6
|
raise 'like can only be called from a model' if self == ApplicationRecord
|
7
7
|
|
8
8
|
queries = nil
|
9
9
|
associations = []
|
10
|
+
schema = [schema] if schema.is_a?(Symbol)
|
10
11
|
@like_query_schema = schema
|
11
12
|
|
12
13
|
(search_string.is_a?(String) ? search_string.split(' ') : search_string).each do |s|
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|