dxlite 0.3.0 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/dxlite.rb +75 -15
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52a6f519b3142ed9207a881bf65f9df9afceed0bc0eccdb258aa46b61988f20e
|
4
|
+
data.tar.gz: 1df9a6b682dc8a05fea3d88152c2d8fdb6042cc75aa246731fa69374568bacfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 641a55501dcada49b36db49c38cbbaf66d94283b9c96f5572a7cfce098b651e899d0d3cdede7561cd2b0ce53b42f3a0b1c97518e39cf12ed75b0ca4ead920cef
|
7
|
+
data.tar.gz: 1b5abceae389e71fd4f813e6cc841abf212eab8db0a56800dc1f627452b454593cf4b86ced042b8ce14a33c6ae34908f3ef90b968f39979fb268cf1feb2781f0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dxlite.rb
CHANGED
@@ -11,15 +11,18 @@ require 'rxfhelper'
|
|
11
11
|
class DxLite
|
12
12
|
using ColouredText
|
13
13
|
|
14
|
-
attr_accessor :summary
|
14
|
+
attr_accessor :summary, :filepath, :schema
|
15
15
|
attr_reader :records
|
16
16
|
|
17
|
-
def initialize(s=nil,
|
17
|
+
def initialize(s=nil, autosave: false, debug: false)
|
18
18
|
|
19
|
-
@
|
19
|
+
@autosave, @debug = autosave, debug
|
20
20
|
|
21
21
|
return unless s
|
22
22
|
buffer, type = RXFHelper.read(s)
|
23
|
+
|
24
|
+
@filepath = s if type == :file or type == :dfs
|
25
|
+
|
23
26
|
puts 'type: ' + type.inspect if @debug
|
24
27
|
puts 'buffer: ' + buffer.inspect if @debug
|
25
28
|
|
@@ -80,16 +83,42 @@ class DxLite
|
|
80
83
|
|
81
84
|
def delete(id)
|
82
85
|
found = @records.find {|x| x[:id] == id}
|
83
|
-
|
86
|
+
|
87
|
+
if found then
|
88
|
+
@records.delete found
|
89
|
+
save() if @autosave
|
90
|
+
end
|
91
|
+
|
84
92
|
end
|
85
93
|
|
86
94
|
def create(rawh, id: nil, custom_attributes: {created: Time.now})
|
95
|
+
|
96
|
+
if id.nil? then
|
97
|
+
|
98
|
+
puts '@records: ' + @records.inspect if @debug
|
99
|
+
|
100
|
+
if @records then
|
101
|
+
id = @records.map {|x| x[:id].to_i}.max.to_i + 1
|
102
|
+
else
|
103
|
+
@records = []
|
104
|
+
id = 1
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
87
108
|
|
88
|
-
id ||= @records.map {|x| x[:id].to_i}.max.to_i + 1
|
89
109
|
h2 = custom_attributes
|
90
|
-
|
91
|
-
|
92
|
-
|
110
|
+
|
111
|
+
fields = rawh.keys
|
112
|
+
puts 'fields: ' + fields.inspect if @debug
|
113
|
+
|
114
|
+
h3 = fields.map {|x| [x.to_sym, nil] }.to_h.merge(rawh)
|
115
|
+
h = {id: id.to_s, created: h2[:created], last_modified: nil, body: h3}
|
116
|
+
@records << h
|
117
|
+
|
118
|
+
save() if @autosave
|
119
|
+
|
120
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
121
|
+
|
93
122
|
end
|
94
123
|
|
95
124
|
def fields()
|
@@ -108,7 +137,9 @@ class DxLite
|
|
108
137
|
if obj.is_a? Array then
|
109
138
|
|
110
139
|
unless schema() then
|
140
|
+
puts 'obj.first: ' + obj.first.inspect if @debug
|
111
141
|
cols = obj.first.keys.map {|c| c == 'id' ? 'uid' : c}
|
142
|
+
puts 'after cols' if @debug
|
112
143
|
self.schema = "items/item(%s)" % cols.join(', ')
|
113
144
|
end
|
114
145
|
|
@@ -155,6 +186,10 @@ class DxLite
|
|
155
186
|
end
|
156
187
|
|
157
188
|
def save(file=@filepath)
|
189
|
+
|
190
|
+
return unless file
|
191
|
+
@filepath = file
|
192
|
+
|
158
193
|
s = File.extname(file) == '.json' ? to_json() : to_xml()
|
159
194
|
File.write file, s
|
160
195
|
end
|
@@ -222,13 +257,20 @@ class DxLite
|
|
222
257
|
end
|
223
258
|
|
224
259
|
r = @records.find {|x| x[:id] == id}
|
225
|
-
|
260
|
+
|
261
|
+
if r then
|
262
|
+
|
263
|
+
r[:body].merge!(obj)
|
264
|
+
save() if @autosave
|
265
|
+
|
266
|
+
end
|
267
|
+
|
226
268
|
end
|
227
269
|
|
228
270
|
private
|
229
271
|
|
230
272
|
def find_record(rec, value, x)
|
231
|
-
value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
273
|
+
r = value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
232
274
|
end
|
233
275
|
|
234
276
|
def make_methods()
|
@@ -251,13 +293,20 @@ class DxLite
|
|
251
293
|
|
252
294
|
define_singleton_method ('find_all_by_' + x).to_sym do |value|
|
253
295
|
|
254
|
-
@records.select {|rec| find_record(rec[:body], value, x) }
|
296
|
+
a = @records.select {|rec| find_record(rec[:body], value, x) }
|
297
|
+
|
298
|
+
a.map do |h|
|
299
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
300
|
+
end
|
255
301
|
|
256
302
|
end
|
257
303
|
|
258
304
|
define_singleton_method ('find_by_' + x).to_sym do |value|
|
259
305
|
|
260
|
-
@records.find {|rec| find_record(rec[:body], value, x) }
|
306
|
+
h = @records.find {|rec| find_record(rec[:body], value, x) }
|
307
|
+
return nil unless h
|
308
|
+
|
309
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
261
310
|
|
262
311
|
end
|
263
312
|
|
@@ -277,9 +326,20 @@ class DxLite
|
|
277
326
|
#puts 'h1:' + h1.inspect if @debug
|
278
327
|
|
279
328
|
h = h1[h1.keys.first]
|
280
|
-
|
281
|
-
|
282
|
-
|
329
|
+
|
330
|
+
@summary = {}
|
331
|
+
|
332
|
+
h[:summary].each do |key, value|
|
333
|
+
|
334
|
+
if %i(recordx_type format_mask schema).include? key then
|
335
|
+
@summary[key] = value
|
336
|
+
else
|
337
|
+
@summary[key.to_s] = value
|
338
|
+
end
|
339
|
+
|
340
|
+
end
|
341
|
+
|
342
|
+
@records = h[:records].map {|x| x[x.keys.first]}
|
283
343
|
|
284
344
|
end
|
285
345
|
|
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
dwbAN6/wokoLVZAiMRG1vZlI6RhtSOTHvFHbfBE5JI9rhjRtui8yeV+t8iI8G4Zs
|
36
36
|
2NszuYzdlVfzlrUiPWY5jL9P
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-
|
38
|
+
date: 2021-02-20 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: recordx
|
metadata.gz.sig
CHANGED
Binary file
|