like_query 0.0.2 → 0.0.4

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: '049ab00db40571bcb74c02122aa68da955b145bd808330336ca5405e9b394c28'
4
+ data.tar.gz: 772e0bc35a1fbb766d2ea2e10fa018bfb9445e2aac5b9fff81aed107b9a43887
5
5
  SHA512:
6
- metadata.gz: 50b1ff03fd06283c506b70a20867261236cae2e2d12f00732efb3a42da474761d817163c77fa8a6eda205b0a96812bb3d7347b86b4adf4184287f53ee1b7dabb
7
- data.tar.gz: 3dd63ff9264451c79616e112885329ddff287ac34abb0dc5df438cba2de4402c8756b30aa65b7ae085c55f0f20e4d1919d02b847032a2b959eee3a55ee38737e
6
+ metadata.gz: 55ad5c0c0bfb442f48b5a9a05fad45ad3fb066c573799dd498ff55f2fb68b1651cf290bde35861d09f4f70fc6cd7cadf65e2b3cdec63bd41ff26bf2876543b07
7
+ data.tar.gz: ed8a996db26473442d8ad3e117d387f4c18bef2f13b9d88749ce5ee1ff5ad0f44df0d3506fbc3880ae30b26e7b3c2584f6d96aee9978421ec735a94461ad5f3c
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,22 +56,19 @@ 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
- cols[:attributes]
61
+ cols[:values]
60
62
  elsif cols.is_a?(Enumerable)
61
63
  cols
62
64
  else
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|
71
- sub_attr.push([c, sub_record.send(c)])
71
+ sub_attr.push(sub_record.send(c))
72
72
  end
73
73
 
74
74
  if @length >= @limit || (limit && length >= limit)
@@ -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 = { values: 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
- rec_attr[:attributes] ||= []
98
- 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
98
+ rec_attr[:values] ||= []
99
+ rec_attr[:values].push(get_column_value(r, p))
104
100
  rec_attr[:id] = r.id
101
+ rec_attr[:model] = r.class.to_s.underscore
105
102
 
106
103
  end
107
104
  end
@@ -109,7 +106,7 @@ module LikeQuery
109
106
  @overflow = true
110
107
  break
111
108
  else
112
- c = (image ? 1 : 0) + rec_attr[:attributes].length
109
+ c = (image ? 1 : 0) + rec_attr[:values].length
113
110
  @columns_count = c if c > @columns_count
114
111
  @data.push(rec_attr)
115
112
  @length += 1
@@ -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.4"
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.4
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