dxlite 0.2.6 → 0.3.3
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 +150 -52
- metadata +8 -7
- 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: b07aaa0e99b004c084971d3d47bec08bd7dc4b2b00ed1744516c8a936d3a770d
|
4
|
+
data.tar.gz: 1354917117fe1e45a811e1e609980dbd83638a04a3cd940d5c88d80a2513b5bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d32f0315a748d91738e7650c4f9636535563732feb283805d3ed0ec45e4ff9efcba278315ae9c276afbc7cb6b19d847df17db99622198715363f6324a4c0337
|
7
|
+
data.tar.gz: '07339c65f3bcc16f9ba435981a0f32d71348778cfdd3f2bcc6e117c51b9988d5773f0e1a4457998b57225bc52c3cd8450849996c9427f8196a5f3d55862889c8'
|
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
|
-
|
74
|
-
define_singleton_method ('find_all_by_' + x).to_sym do |value|
|
75
|
-
|
76
|
-
@records.select {|rec| find_record(rec[:body], value, x) }
|
77
|
-
|
78
|
-
end
|
79
62
|
|
80
|
-
|
81
|
-
|
82
|
-
@records.find {|rec| find_record(rec[:body], value, x) }
|
83
|
-
|
63
|
+
summary.split(/ *, */).each do |x|
|
64
|
+
@summary[x] = nil unless @summary[x]
|
84
65
|
end
|
85
|
-
|
86
|
-
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
make_methods()
|
87
70
|
|
88
71
|
end
|
89
72
|
|
@@ -100,14 +83,27 @@ 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
|
+
h = fields.map {|x| [x.to_sym, nil] }.to_h.merge(rawh)
|
99
|
+
@records << {id: id.to_s, created: h2[:created], last_modified: nil,
|
100
|
+
body: h}
|
101
|
+
|
102
|
+
save() if @autosave
|
103
|
+
end
|
104
|
+
|
105
|
+
def fields()
|
106
|
+
@fields
|
111
107
|
end
|
112
108
|
|
113
109
|
def inspect()
|
@@ -127,7 +123,7 @@ class DxLite
|
|
127
123
|
end
|
128
124
|
|
129
125
|
obj.each do |x|
|
130
|
-
puts 'x: ' + x.inspect if @debug
|
126
|
+
#puts 'x: ' + x.inspect if @debug
|
131
127
|
self.create x, id: nil
|
132
128
|
end
|
133
129
|
|
@@ -137,12 +133,49 @@ class DxLite
|
|
137
133
|
end
|
138
134
|
|
139
135
|
alias import parse
|
136
|
+
|
137
|
+
def parse_xml(buffer)
|
138
|
+
|
139
|
+
doc = Rexle.new(buffer)
|
140
|
+
|
141
|
+
asummary = doc.root.xpath('summary/*').map do |node|
|
142
|
+
puts 'node: ' + node.xml.inspect if @debug
|
143
|
+
[node.name, node.text.to_s]
|
144
|
+
end
|
145
|
+
|
146
|
+
summary = Hash[asummary]
|
147
|
+
summary[:schema] = summary['schema']
|
148
|
+
%w(recordx_type format_mask schema).each {|x| summary.delete x}
|
149
|
+
|
150
|
+
schema = summary[:schema]
|
151
|
+
puts 'schema: ' + schema.inspect if @debug
|
152
|
+
|
153
|
+
@fields = schema[/\(([^\)]+)/,1].split(/ *, +/)
|
154
|
+
puts 'fields: ' + @fields.inspect if @debug
|
155
|
+
|
156
|
+
a = doc.root.xpath('records/*').each do |node|
|
157
|
+
|
158
|
+
h = Hash[@fields.map {|field| [field.to_sym, node.text(field).to_s] }]
|
159
|
+
self.create h, id: nil
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
@summary = summary
|
164
|
+
|
165
|
+
end
|
140
166
|
|
141
167
|
def save(file=@filepath)
|
142
|
-
|
168
|
+
|
169
|
+
return unless file
|
170
|
+
@filepath = file
|
171
|
+
|
172
|
+
s = File.extname(file) == '.json' ? to_json() : to_xml()
|
173
|
+
File.write file, s
|
143
174
|
end
|
144
175
|
|
145
|
-
|
176
|
+
def to_a()
|
177
|
+
@records.map {|x| x[:body]}
|
178
|
+
end
|
146
179
|
|
147
180
|
def to_h()
|
148
181
|
|
@@ -203,25 +236,90 @@ class DxLite
|
|
203
236
|
end
|
204
237
|
|
205
238
|
r = @records.find {|x| x[:id] == id}
|
206
|
-
|
239
|
+
|
240
|
+
if r then
|
241
|
+
|
242
|
+
r[:body].merge!(obj)
|
243
|
+
save() if @autosave
|
244
|
+
|
245
|
+
end
|
246
|
+
|
207
247
|
end
|
208
248
|
|
209
249
|
private
|
210
250
|
|
211
251
|
def find_record(rec, value, x)
|
212
|
-
value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
252
|
+
r = value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
213
253
|
end
|
214
254
|
|
215
|
-
def
|
255
|
+
def make_methods()
|
216
256
|
|
217
|
-
|
218
|
-
puts 'h1:' + h1.inspect if @debug
|
257
|
+
# for each summary item create get and set methods
|
219
258
|
|
220
|
-
|
259
|
+
@summary.each do |key, value|
|
260
|
+
|
261
|
+
define_singleton_method(key) { @summary[key] }
|
262
|
+
|
263
|
+
define_singleton_method (key.to_s + '=').to_sym do |value|
|
264
|
+
@summary[key] = value
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
221
268
|
|
222
|
-
@
|
223
|
-
|
269
|
+
@fields = @summary[:schema][/(?<=\()[^\)]+/].split(',').map(&:strip)
|
270
|
+
|
271
|
+
@fields.each do |x|
|
272
|
+
|
273
|
+
define_singleton_method ('find_all_by_' + x).to_sym do |value|
|
274
|
+
|
275
|
+
a = @records.select {|rec| find_record(rec[:body], value, x) }
|
276
|
+
|
277
|
+
a.map do |h|
|
278
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
define_singleton_method ('find_by_' + x).to_sym do |value|
|
284
|
+
|
285
|
+
h = @records.find {|rec| find_record(rec[:body], value, x) }
|
286
|
+
RecordX.new(h[:body], self, h[:id], h[:created], h[:last_modified])
|
287
|
+
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|
293
|
+
|
294
|
+
def read(buffer)
|
224
295
|
|
296
|
+
if buffer[0] == '<' then
|
297
|
+
|
298
|
+
parse_xml buffer
|
299
|
+
|
300
|
+
else
|
301
|
+
|
302
|
+
h1 = JSON.parse(buffer, symbolize_names: true)
|
303
|
+
#puts 'h1:' + h1.inspect if @debug
|
304
|
+
|
305
|
+
h = h1[h1.keys.first]
|
306
|
+
|
307
|
+
@summary = {}
|
308
|
+
|
309
|
+
h[:summary].each do |key, value|
|
310
|
+
|
311
|
+
if %i(recordx_type format_mask schema).include? key then
|
312
|
+
@summary[key] = value
|
313
|
+
else
|
314
|
+
@summary[key.to_s] = value
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
@records = h[:records].map {|x| x[x.keys.first]}
|
320
|
+
|
321
|
+
end
|
322
|
+
|
225
323
|
end
|
226
324
|
|
227
325
|
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.3
|
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-29 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: recordx
|
@@ -63,20 +63,20 @@ dependencies:
|
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '1.
|
66
|
+
version: '1.1'
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
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
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '1.
|
76
|
+
version: '1.1'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 1.
|
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
|