dxlite 0.6.1 → 0.6.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: cdef9eda0edd930a2698134328be46b4be487c13f3125e38b30e36e93ca5d22f
4
- data.tar.gz: e44e9f3791b109b90e139ae749defcf7014adbbc21d642fb8aca70cd4378ce4e
3
+ metadata.gz: 250500a33175fd75751304e636127328659be1d479c69fc821eec449fc14c898
4
+ data.tar.gz: a0ec8ec56a0830de7d4eefae7dd384fa56916383cabb1cbc9ce373c822f454d7
5
5
  SHA512:
6
- metadata.gz: a8875b822287ebd3037ccf1cff2ecd39dafcc70a6d99f75b35006448503f5624e1f7fd5dc61ccd6e1d909bb7a78331b5c39832dc0d9f3af7a751ea24e4f65fc5
7
- data.tar.gz: d6abb77ad3dcfdddb2aa30449204286e2be4f7db49f0425380b8d8384212c58fcff9afc3af25f1b45c986c48471be91517bb8958a2a7e1fd49d32dc85dcd7f80
6
+ metadata.gz: 7d74c9420396ec5de7c476d9a0a20eb3dc67ab43137cd2bbc3d3ed7be30cd278a976ac11640013b855c4b2a825a06e5cb2706e57eb8dee09149022415ffd8b00
7
+ data.tar.gz: 4e9cc5c15f1afac57c0818a7a90d31c132332e8c698d02c4dda649af0c45f9fc7e79d1f8ff762cd523e16ef4fbb9fb3684e77e12a14089cd278691339c12e0b2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/dxlite.rb CHANGED
@@ -25,7 +25,7 @@ class DxLite
25
25
  attr_accessor :summary, :filepath
26
26
  attr_reader :records, :schema
27
27
 
28
- def initialize(s=nil, autosave: false, debug: false)
28
+ def initialize(s=nil, autosave: false, order: 'ascending', debug: false)
29
29
 
30
30
  @autosave, @debug = autosave, debug
31
31
 
@@ -51,7 +51,7 @@ class DxLite
51
51
 
52
52
  when :text
53
53
 
54
- new_summary(s)
54
+ new_summary(s, order)
55
55
 
56
56
  when :url
57
57
 
@@ -94,8 +94,16 @@ class DxLite
94
94
  if key then
95
95
 
96
96
  r = records.find {|x| x[:body][key.to_sym] == rawh[key.to_sym]}
97
+
97
98
  if r then
99
+
100
+ # if the client is using create() instead of update() to update a
101
+ # record then update the record
102
+ #
103
+ r[:body].merge!(rawh)
98
104
  r[:last_modified] = Time.now.to_s
105
+ save() if @autosave
106
+
99
107
  return false
100
108
  end
101
109
 
@@ -133,6 +141,17 @@ class DxLite
133
141
  @fields
134
142
  end
135
143
 
144
+ def record(id)
145
+
146
+ h = @records.find {|x| x[:id] == id }
147
+ return unless h
148
+ RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
149
+
150
+ end
151
+
152
+ alias find record
153
+ alias find_by_id record
154
+
136
155
  def inspect()
137
156
  "#<DxLite:%s @debug=%s, @summary=%s, ...>" % [object_id, @debug,
138
157
  @summary.inspect]
@@ -213,11 +232,40 @@ class DxLite
213
232
  root_name = schema()[/^\w+/]
214
233
  record_name = schema()[/(?<=\/)[^\(]+/]
215
234
 
235
+ records = @records.map {|h| {record_name.to_sym => h} }
236
+
237
+ a = if @summary[:order] == 'descending' then
238
+
239
+ records.sort_by do |x|
240
+
241
+ if @debug then
242
+ puts 'x: ' + x.inspect
243
+ puts 'created: ' + Date.parse(x[:post][:created]).inspect
244
+ end
245
+
246
+ created = DateTime.parse(x[:post][:created])
247
+
248
+ last_modified = if x[:post][:last_modified] then
249
+ DateTime.parse(x[:post][:last_modified])
250
+ else
251
+ nil
252
+ end
253
+
254
+ last_modified || created
255
+
256
+ end.reverse
257
+
258
+ else
259
+
260
+ records
261
+
262
+ end
263
+
216
264
  h = {
217
265
  root_name.to_sym =>
218
266
  {
219
267
  summary: @summary,
220
- records: @records.map {|h| {record_name.to_sym => h} }
268
+ records: a
221
269
  }
222
270
  }
223
271
 
@@ -271,6 +319,7 @@ class DxLite
271
319
  if r then
272
320
 
273
321
  r[:body].merge!(obj)
322
+ r[:last_modified] = Time.now
274
323
  save() if @autosave
275
324
 
276
325
  end
@@ -324,7 +373,7 @@ class DxLite
324
373
 
325
374
  end
326
375
 
327
- def new_summary(schema)
376
+ def new_summary(schema, order)
328
377
 
329
378
  @summary = {schema: schema}
330
379
 
@@ -333,7 +382,8 @@ class DxLite
333
382
 
334
383
  summary_attributes = {
335
384
  recordx_type: 'dynarex',
336
- default_key: schema[/(?<=\()\w+/]
385
+ default_key: schema[/(?<=\()\w+/],
386
+ order: order
337
387
  }
338
388
 
339
389
  puts 'before merge' if @debug
@@ -369,7 +419,8 @@ class DxLite
369
419
 
370
420
  h[:summary].each do |key, value|
371
421
 
372
- if %i(recordx_type format_mask schema default_key).include? key then
422
+ if %i(recordx_type format_mask schema default_key order)\
423
+ .include? key then
373
424
  @summary[key] = value
374
425
  else
375
426
  @summary[key.to_s] = value
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dxlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  9pK+pqislEMFrWscGeMsc6YMS7ALxEujTuwTWyxmWAXnYft4ff2O1Zh2sPmdOlgf
36
36
  camg7d8q+VZZzAtz0cFc4pip
37
37
  -----END CERTIFICATE-----
38
- date: 2022-03-18 00:00:00.000000000 Z
38
+ date: 2022-03-21 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: recordx
@@ -43,20 +43,20 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.5'
46
+ version: '0.6'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.5.5
49
+ version: 0.6.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0.5'
56
+ version: '0.6'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.5.5
59
+ version: 0.6.0
60
60
  description:
61
61
  email: digital.robertson@gmail.com
62
62
  executables: []
metadata.gz.sig CHANGED
Binary file