like_query 0.0.2 → 0.0.3
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 +13 -11
- data/lib/like_query/collect.rb +12 -13
- 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: eb533ef11731913bdf3356f5177354cbdc85b4506ba2aae392f7149b7fe7e6d2
|
4
|
+
data.tar.gz: 4b256fb9aa9336559e6a9fc529e7376fae1f6fc09da1cd9b662eb18dd770c5dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fdeaadc79ef10c0690dff7d0213d8241ea0f01679fdb1494d95bb4b9f975813ef5319ae2639a431bb291793ca74ceb1902ca11e9ba5ad9b7423f114c4b3ed0e
|
7
|
+
data.tar.gz: 7d53223f4fe56b448e28aebb46e3db3f400de45b7698a5a3526543612180f4a937951733ade9cff093e177e9d4340fd50b90cc132ea64be811cde32ab2440e7b
|
data/README.md
CHANGED
@@ -47,22 +47,24 @@ art1 = Article.create(name: 'first', number: '01', customer: customer)
|
|
47
47
|
|
48
48
|
Article.like('fir', :name).like_result(limit: 10)
|
49
49
|
# returns:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
{
|
51
|
+
:data=>[
|
52
|
+
{
|
53
|
+
:attributes=>[[:name, "first"]],
|
54
|
+
:id=>1}],
|
55
|
+
:length=>1,
|
56
|
+
:overflow=>false,
|
57
|
+
:columns_count=>1,
|
58
|
+
:sub_records_columns_count=>0
|
59
|
+
}
|
60
60
|
|
61
61
|
Article.like('fir', :name).like_result( :number, limit: 10)
|
62
62
|
# would query like the above example: Search scope is only :name
|
63
63
|
# but would return article-number instead of article-name inside the data block
|
64
64
|
```
|
65
65
|
|
66
|
+
`#like_result` uses `LikeQuery::Collect`, functionality is the same.
|
67
|
+
|
66
68
|
**Class LikeQuery::Collect**
|
67
69
|
|
68
70
|
```ruby
|
@@ -80,7 +82,7 @@ c.receive { Customer.like('any-art', :name, image: :image_column, articles: :nam
|
|
80
82
|
# => otherwise it would add Customers to the result hash
|
81
83
|
|
82
84
|
c.result
|
83
|
-
# => would return anything like:
|
85
|
+
# => would return anything like (this output is from different code!!):
|
84
86
|
{
|
85
87
|
:data=>[
|
86
88
|
{:attributes=>[[:name, "Ambühl"]], :id=>1, :image=>"src:customer-image",
|
data/lib/like_query/collect.rb
CHANGED
@@ -7,6 +7,8 @@ module LikeQuery
|
|
7
7
|
@overflow = false
|
8
8
|
@columns_count = 0
|
9
9
|
@sub_records_columns_count = 0
|
10
|
+
@image = false
|
11
|
+
@sub_records_image = false
|
10
12
|
end
|
11
13
|
|
12
14
|
def receive(*result_pattern, limit: nil, image: nil, &block)
|
@@ -45,6 +47,7 @@ module LikeQuery
|
|
45
47
|
# IMAGE COLUMN
|
46
48
|
|
47
49
|
rec_attr[:image] = get_column_value(r, cols)
|
50
|
+
@image = true
|
48
51
|
|
49
52
|
else
|
50
53
|
|
@@ -53,7 +56,6 @@ module LikeQuery
|
|
53
56
|
sub_records = r.send(assoc)
|
54
57
|
image_column = nil
|
55
58
|
|
56
|
-
|
57
59
|
_cols = if cols.is_a?(Hash)
|
58
60
|
image_column = cols[:image]
|
59
61
|
cols[:attributes]
|
@@ -63,8 +65,6 @@ module LikeQuery
|
|
63
65
|
[cols]
|
64
66
|
end
|
65
67
|
|
66
|
-
|
67
|
-
#_cols = (cols.is_a?(Enumerable) ? cols : [cols])
|
68
68
|
(sub_records.is_a?(Enumerable) ? sub_records : [sub_records]).each do |sub_record|
|
69
69
|
sub_attr = []
|
70
70
|
_cols.each do |c|
|
@@ -79,8 +79,11 @@ module LikeQuery
|
|
79
79
|
@sub_records_columns_count = c if c > @sub_records_columns_count
|
80
80
|
rec_attr[:associations] ||= {}
|
81
81
|
rec_attr[:associations][assoc] ||= []
|
82
|
-
sub_hash = { attributes: sub_attr, id: sub_record.id }
|
83
|
-
|
82
|
+
sub_hash = { attributes: sub_attr, id: sub_record.id, model: sub_record.class.to_s.underscore }
|
83
|
+
if image_column
|
84
|
+
sub_hash[:image] = get_column_value(sub_record, image_column)
|
85
|
+
@sub_records_image = true
|
86
|
+
end
|
84
87
|
rec_attr[:associations][assoc].push(sub_hash)
|
85
88
|
@length += 1
|
86
89
|
length += 1
|
@@ -92,16 +95,10 @@ module LikeQuery
|
|
92
95
|
|
93
96
|
# MAIN RECORD
|
94
97
|
|
95
|
-
# v = nil
|
96
|
-
# p.to_s.split('.').each { |_p| v = (v ? v : r).send(_p) }
|
97
98
|
rec_attr[:attributes] ||= []
|
98
99
|
rec_attr[:attributes].push([p, get_column_value(r, p)])
|
99
|
-
# if image
|
100
|
-
# img = nil
|
101
|
-
# image.to_s.split('.').each { |i| img = (img ? img : r).send(i) }
|
102
|
-
# rec_attr[:image] = img
|
103
|
-
# end
|
104
100
|
rec_attr[:id] = r.id
|
101
|
+
rec_attr[:model] = r.class.to_s.underscore
|
105
102
|
|
106
103
|
end
|
107
104
|
end
|
@@ -126,7 +123,9 @@ module LikeQuery
|
|
126
123
|
length: @length,
|
127
124
|
overflow: @overflow,
|
128
125
|
columns_count: @columns_count,
|
129
|
-
sub_records_columns_count: @sub_records_columns_count
|
126
|
+
sub_records_columns_count: @sub_records_columns_count,
|
127
|
+
image: @image,
|
128
|
+
sub_records_image: @sub_records_image
|
130
129
|
}
|
131
130
|
end
|
132
131
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|