like_query 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d2dc6db9752704bd4ddb724dad78fd1af88bbbc9a865ab4ac4e1d9f879118a4
4
- data.tar.gz: 5d42e509c6723aeffe2bb27626ac2a511f725e6c88ff56ab101220135839540e
3
+ metadata.gz: 88909f6d5d1906a27c6cb848f7fad43a711666bae3f21a4241da60f26a73041a
4
+ data.tar.gz: f88b8e02d010380d4f71ce258b32991340240402ed666dc269a1e6bfc0c02083
5
5
  SHA512:
6
- metadata.gz: e5e6924e36cb86fd1b3fcc27786575b3c04ac0381583c891574a000f3b89c44aedc9402b476ddb8db0f1738658ba5eae51226014e2ef9a3758b2382d510ad8f9
7
- data.tar.gz: a2146917979e4a67490848ccc3eee98b9d70651bdf9aca7fb2f91848671092724cbcc7840ebd22ef3e3081c010b15308ea9ceb98a807bbcb2fc404dd032c9884
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.
@@ -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)
@@ -135,6 +136,7 @@ module LikeQuery
135
136
  end
136
137
  r[:image] = record.send(image) if image
137
138
  r[:url] = url.yield(record) if url
139
+ r[:no_action] = true if @no_action[record.class.to_s]
138
140
  r
139
141
  end
140
142
 
@@ -1,12 +1,13 @@
1
1
  module LikeQuery
2
2
  module ModelExtensions
3
3
 
4
- def like(search_string, *schema)
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|
@@ -1,3 +1,3 @@
1
1
  module LikeQuery
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
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.12
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-06 00:00:00.000000000 Z
11
+ date: 2023-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails