dxlite 0.2.7 → 0.3.4
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 +155 -52
- metadata +12 -11
- 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: 28362d972f8389e1b817f21be4fb9524ca4188761b4f4128c21a886eb67a11a5
|
4
|
+
data.tar.gz: df45a19238f82766d2abd14f08dc0f105b6bb1d66e4ddf85c46e4089f2600c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 515c3ed54028756c1ff4a5e660f204b878b0c2098f8de61ac43096c7b3191d2a2ffaf9b8d1f0a5f8fed62d80dd22845661c2927bc40bddc5a44c02986e1b32bc
|
7
|
+
data.tar.gz: e8aa916f1ebf5118440c45d75c75ec116d64cd98215ba1a0b9d85c49d8c4d92530d7686f1833097506f6453e8370587700c1dd67aba88ab51ff4ee0c24703932
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dxlite.rb
CHANGED
@@ -11,17 +11,23 @@ require 'rxfhelper'
|
|
11
11
|
class DxLite
|
12
12
|
using ColouredText
|
13
13
|
|
14
|
-
attr_accessor :summary
|
14
|
+
attr_accessor :summary, :filepath
|
15
15
|
attr_reader :records
|
16
16
|
|
17
|
-
def initialize(s,
|
17
|
+
def initialize(s=nil, autosave: false, debug: false)
|
18
18
|
|
19
|
-
@
|
19
|
+
@autosave, @debug = autosave, debug
|
20
20
|
|
21
|
+
return unless s
|
21
22
|
buffer, type = RXFHelper.read(s)
|
23
|
+
|
24
|
+
@filepath = s if type == :file or type == :dfs
|
25
|
+
|
22
26
|
puts 'type: ' + type.inspect if @debug
|
23
27
|
puts 'buffer: ' + buffer.inspect if @debug
|
24
|
-
|
28
|
+
|
29
|
+
@records = []
|
30
|
+
|
25
31
|
case type
|
26
32
|
|
27
33
|
when :file
|
@@ -31,7 +37,7 @@ class DxLite
|
|
31
37
|
when :text
|
32
38
|
|
33
39
|
@summary = {schema: s}
|
34
|
-
|
40
|
+
|
35
41
|
|
36
42
|
when :url
|
37
43
|
|
@@ -39,51 +45,28 @@ class DxLite
|
|
39
45
|
|
40
46
|
end
|
41
47
|
|
42
|
-
|
48
|
+
puts '@summary: ' + @summary.inspect
|
43
49
|
@schema = @summary[:schema]
|
44
50
|
|
45
51
|
summary_attributes = {
|
46
52
|
recordx_type: 'dynarex',
|
47
|
-
default_key: @schema[/(?<=\()\w+/]
|
53
|
+
default_key: @schema[/(?<=\()\w+/]
|
48
54
|
}
|
49
|
-
|
55
|
+
|
56
|
+
puts 'before merge' if @debug
|
50
57
|
@summary.merge!(summary_attributes)
|
51
58
|
|
52
59
|
summary = @summary[:schema][/(?<=\[)[^\]]+/]
|
53
60
|
|
54
61
|
if summary then
|
55
|
-
@summary.merge! summary.split(',').map {|x|[x.strip, nil] }.to_h
|
56
|
-
end
|
57
|
-
|
58
|
-
# for each summary item create get and set methods
|
59
|
-
|
60
|
-
@summary.each do |key, value|
|
61
|
-
|
62
|
-
define_singleton_method(key) { @summary[key] }
|
63
|
-
|
64
|
-
define_singleton_method (key.to_s + '=').to_sym do |value|
|
65
|
-
@summary[key] = value
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
@fields = @summary[:schema][/(?<=\()[^\)]+/].split(',').map(&:strip)
|
71
|
-
|
72
|
-
@fields.each do |x|
|
73
62
|
|
74
|
-
|
75
|
-
|
76
|
-
@records.select {|rec| find_record(rec[:body], value, x) }
|
77
|
-
|
63
|
+
summary.split(/ *, */).each do |x|
|
64
|
+
@summary[x] = nil unless @summary[x]
|
78
65
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
make_methods()
|
87
70
|
|
88
71
|
end
|
89
72
|
|
@@ -100,14 +83,30 @@ class DxLite
|
|
100
83
|
|
101
84
|
def delete(id)
|
102
85
|
found = @records.find {|x| x[:id] == id}
|
103
|
-
|
86
|
+
|
87
|
+
if found then
|
88
|
+
@records.delete found
|
89
|
+
save() if @autosave
|
90
|
+
end
|
91
|
+
|
104
92
|
end
|
105
93
|
|
106
|
-
def create(
|
94
|
+
def create(rawh, id: nil, custom_attributes: {created: Time.now})
|
107
95
|
|
108
96
|
id ||= @records.map {|x| x[:id].to_i}.max.to_i + 1
|
109
97
|
h2 = custom_attributes
|
110
|
-
|
98
|
+
h3 = fields.map {|x| [x.to_sym, nil] }.to_h.merge(rawh)
|
99
|
+
h = {id: id.to_s, created: h2[:created], last_modified: nil, body: h3}
|
100
|
+
@records << h
|
101
|
+
|
102
|
+
save() if @autosave
|
103
|
+
|
104
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
def fields()
|
109
|
+
@fields
|
111
110
|
end
|
112
111
|
|
113
112
|
def inspect()
|
@@ -127,7 +126,7 @@ class DxLite
|
|
127
126
|
end
|
128
127
|
|
129
128
|
obj.each do |x|
|
130
|
-
puts 'x: ' + x.inspect if @debug
|
129
|
+
#puts 'x: ' + x.inspect if @debug
|
131
130
|
self.create x, id: nil
|
132
131
|
end
|
133
132
|
|
@@ -137,12 +136,49 @@ class DxLite
|
|
137
136
|
end
|
138
137
|
|
139
138
|
alias import parse
|
139
|
+
|
140
|
+
def parse_xml(buffer)
|
141
|
+
|
142
|
+
doc = Rexle.new(buffer)
|
143
|
+
|
144
|
+
asummary = doc.root.xpath('summary/*').map do |node|
|
145
|
+
puts 'node: ' + node.xml.inspect if @debug
|
146
|
+
[node.name, node.text.to_s]
|
147
|
+
end
|
148
|
+
|
149
|
+
summary = Hash[asummary]
|
150
|
+
summary[:schema] = summary['schema']
|
151
|
+
%w(recordx_type format_mask schema).each {|x| summary.delete x}
|
152
|
+
|
153
|
+
schema = summary[:schema]
|
154
|
+
puts 'schema: ' + schema.inspect if @debug
|
155
|
+
|
156
|
+
@fields = schema[/\(([^\)]+)/,1].split(/ *, +/)
|
157
|
+
puts 'fields: ' + @fields.inspect if @debug
|
158
|
+
|
159
|
+
a = doc.root.xpath('records/*').each do |node|
|
160
|
+
|
161
|
+
h = Hash[@fields.map {|field| [field.to_sym, node.text(field).to_s] }]
|
162
|
+
self.create h, id: nil
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
@summary = summary
|
167
|
+
|
168
|
+
end
|
140
169
|
|
141
170
|
def save(file=@filepath)
|
142
|
-
|
171
|
+
|
172
|
+
return unless file
|
173
|
+
@filepath = file
|
174
|
+
|
175
|
+
s = File.extname(file) == '.json' ? to_json() : to_xml()
|
176
|
+
File.write file, s
|
143
177
|
end
|
144
178
|
|
145
|
-
|
179
|
+
def to_a()
|
180
|
+
@records.map {|x| x[:body]}
|
181
|
+
end
|
146
182
|
|
147
183
|
def to_h()
|
148
184
|
|
@@ -203,25 +239,92 @@ class DxLite
|
|
203
239
|
end
|
204
240
|
|
205
241
|
r = @records.find {|x| x[:id] == id}
|
206
|
-
|
242
|
+
|
243
|
+
if r then
|
244
|
+
|
245
|
+
r[:body].merge!(obj)
|
246
|
+
save() if @autosave
|
247
|
+
|
248
|
+
end
|
249
|
+
|
207
250
|
end
|
208
251
|
|
209
252
|
private
|
210
253
|
|
211
254
|
def find_record(rec, value, x)
|
212
|
-
value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
255
|
+
r = value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
213
256
|
end
|
214
257
|
|
215
|
-
def
|
258
|
+
def make_methods()
|
216
259
|
|
217
|
-
|
218
|
-
puts 'h1:' + h1.inspect if @debug
|
260
|
+
# for each summary item create get and set methods
|
219
261
|
|
220
|
-
|
262
|
+
@summary.each do |key, value|
|
263
|
+
|
264
|
+
define_singleton_method(key) { @summary[key] }
|
265
|
+
|
266
|
+
define_singleton_method (key.to_s + '=').to_sym do |value|
|
267
|
+
@summary[key] = value
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
221
271
|
|
222
|
-
@
|
223
|
-
|
272
|
+
@fields = @summary[:schema][/(?<=\()[^\)]+/].split(',').map(&:strip)
|
273
|
+
|
274
|
+
@fields.each do |x|
|
275
|
+
|
276
|
+
define_singleton_method ('find_all_by_' + x).to_sym do |value|
|
277
|
+
|
278
|
+
a = @records.select {|rec| find_record(rec[:body], value, x) }
|
279
|
+
|
280
|
+
a.map do |h|
|
281
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
define_singleton_method ('find_by_' + x).to_sym do |value|
|
287
|
+
|
288
|
+
h = @records.find {|rec| find_record(rec[:body], value, x) }
|
289
|
+
return nil unless h
|
290
|
+
|
291
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
def read(buffer)
|
300
|
+
|
301
|
+
if buffer[0] == '<' then
|
224
302
|
|
303
|
+
parse_xml buffer
|
304
|
+
|
305
|
+
else
|
306
|
+
|
307
|
+
h1 = JSON.parse(buffer, symbolize_names: true)
|
308
|
+
#puts 'h1:' + h1.inspect if @debug
|
309
|
+
|
310
|
+
h = h1[h1.keys.first]
|
311
|
+
|
312
|
+
@summary = {}
|
313
|
+
|
314
|
+
h[:summary].each do |key, value|
|
315
|
+
|
316
|
+
if %i(recordx_type format_mask schema).include? key then
|
317
|
+
@summary[key] = value
|
318
|
+
else
|
319
|
+
@summary[key.to_s] = value
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
@records = h[:records].map {|x| x[x.keys.first]}
|
325
|
+
|
326
|
+
end
|
327
|
+
|
225
328
|
end
|
226
329
|
|
227
330
|
end
|
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.
|
4
|
+
version: 0.3.4
|
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:
|
38
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: recordx
|
@@ -61,22 +61,22 @@ dependencies:
|
|
61
61
|
name: rxfhelper
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 1.0.0
|
67
64
|
- - "~>"
|
68
65
|
- !ruby/object:Gem::Version
|
69
|
-
version: '1.
|
66
|
+
version: '1.1'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.3
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.0.0
|
77
74
|
- - "~>"
|
78
75
|
- !ruby/object:Gem::Version
|
79
|
-
version: '1.
|
76
|
+
version: '1.1'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.1.3
|
80
80
|
description:
|
81
81
|
email: james@jamesrobertson.eu
|
82
82
|
executables: []
|
@@ -103,7 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.10
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Handles Dynarex documents (in JSON format) faster and with less overheads.
|
metadata.gz.sig
CHANGED
Binary file
|