like_query 0.0.12 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/like_query/collect.rb +4 -2
- data/lib/like_query/extender.rb +7 -0
- data/lib/like_query/model_extensions.rb +2 -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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d4230b3b33d18fab9361c9146858a63b0ef5a9cc139f822cba599e4ff5e9466
|
4
|
+
data.tar.gz: 57ea4af2fe5206f68858c1ab03bfd610568fca5567daef4083439d494a208080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5676c9773c9003eb4e8461b98f12aace86c20f765968ab9985810ecb4b1de67803414ee6f6c4481546acf372e579e2f60eafc0a0367639725e754c198a3a91bd
|
7
|
+
data.tar.gz: 2e3f116f4b43b8519cb148104416038350d4ebef5a63fc22201101e025678acc54b08a8a2fc06ae8cbf115c5754441cb798a4541d66f8d9fb04e6fcba8adbfa0
|
data/README.md
CHANGED
@@ -206,6 +206,47 @@ Otherwise `#generate_hash` would not know what values to return.
|
|
206
206
|
r = c.generate_hash
|
207
207
|
```
|
208
208
|
|
209
|
+
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.
|
210
|
+
|
211
|
+
**url**
|
212
|
+
|
213
|
+
You can also use the handy Rails url generators to avoid having to build urls tediously with javascript on the frontend:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
customer = Customer.create(name: 'Ambühl')
|
217
|
+
proc1 = proc {|cust| customer_path(cust)}
|
218
|
+
r = Customer.like('ambühl', :name).generate_hash(:name, url: proc1)
|
219
|
+
r[:data].first[:url] #=> "/customer/#{customer.id}"
|
220
|
+
```
|
221
|
+
or
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
customer = Customer.create(name: 'Ambühl')
|
225
|
+
c = LikeQuery::Collect.new
|
226
|
+
proc1 = proc {|cust| customer_path(cust)}
|
227
|
+
c.collect(url: proc1) { Customer.like('ambühl', :name) }
|
228
|
+
r = c.generate_hash
|
229
|
+
r[:data].first[:url] #=> "/customer/#{customer.id}"
|
230
|
+
```
|
231
|
+
|
232
|
+
or
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
customer = Customer.create(name: 'Ambühl')
|
236
|
+
art = Article.create(number: 'art-no', customer: customer)
|
237
|
+
c = LikeQuery::Collect.new
|
238
|
+
proc1 = proc {|cust| customer_path(cust)}
|
239
|
+
|
240
|
+
c.collect(url: proc1) { Customer.like('xyxyxyyxy', :number) }
|
241
|
+
# remember url although nothing found
|
242
|
+
|
243
|
+
proc2 = proc {|article| customer_article_path(article.customer, article) }
|
244
|
+
c.collect(parent: :customer, url: proc2) { Article.like('art', :number) }
|
245
|
+
r = c.generate_hash
|
246
|
+
r[:data].first[:url] #=> "/customer/#{customer.id}"
|
247
|
+
r[:data].first[:children].first[:url] #=> "/customer/#{customer.id}/article/#{art.id}"
|
248
|
+
```
|
249
|
+
|
209
250
|
**Performance**
|
210
251
|
|
211
252
|
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)
|
@@ -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,
|
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/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.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-11 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
|