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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12f503e7aa188d223e922496909dabff55b2ff5c843e18ed23ae5525a5190dfa
4
- data.tar.gz: fa7edce57c33d96b1c040767f5e41a95d32573b78cbc259ade1411178748a941
3
+ metadata.gz: eb533ef11731913bdf3356f5177354cbdc85b4506ba2aae392f7149b7fe7e6d2
4
+ data.tar.gz: 4b256fb9aa9336559e6a9fc529e7376fae1f6fc09da1cd9b662eb18dd770c5dd
5
5
  SHA512:
6
- metadata.gz: 50b1ff03fd06283c506b70a20867261236cae2e2d12f00732efb3a42da474761d817163c77fa8a6eda205b0a96812bb3d7347b86b4adf4184287f53ee1b7dabb
7
- data.tar.gz: 3dd63ff9264451c79616e112885329ddff287ac34abb0dc5df438cba2de4402c8756b30aa65b7ae085c55f0f20e4d1919d02b847032a2b959eee3a55ee38737e
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
- # :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
- # }
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",
@@ -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
- sub_hash[:image] = get_column_value(sub_record, image_column) if image_column
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
 
@@ -1,3 +1,3 @@
1
1
  module LikeQuery
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
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-26 00:00:00.000000000 Z
11
+ date: 2023-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails