dxlite 0.2.3 → 0.2.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/dxlite.rb +72 -11
- metadata +3 -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: 17e3592686fa48db902f98d0d7dce8ed09b6bca4d2f42b36994bb940d47b5fd4
|
4
|
+
data.tar.gz: 6b2cb9ae5b94c25880b369e6bd558ca02005564bfaa96a810532963faba6fabd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 241329fd8c70eb330cd70ea488c25f6fdbcc6ca0a062b3a3f3ce40bc43b65bb0207d4a25ce9ba8184ad457ebd574bbc4ff7025a6095d9d231eff6184b99ea80c
|
7
|
+
data.tar.gz: d57fac1b246db2e6915a4f8d4ce64341aba08a9e683a7a26d1692a13828756bafc75995664fde5369ff8e0ec9aafb7bf2ec50588c15ea6ded2c9d9b37e149ee6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dxlite.rb
CHANGED
@@ -7,6 +7,7 @@ require 'json'
|
|
7
7
|
require 'recordx'
|
8
8
|
require 'rxfhelper'
|
9
9
|
|
10
|
+
|
10
11
|
class DxLite
|
11
12
|
using ColouredText
|
12
13
|
|
@@ -24,9 +25,12 @@ class DxLite
|
|
24
25
|
|
25
26
|
when :file
|
26
27
|
|
27
|
-
|
28
|
+
h1 = JSON.parse(buffer, symbolize_names: true)
|
29
|
+
puts 'h1:' + h1.inspect if @debug
|
28
30
|
@filepath = s
|
29
31
|
|
32
|
+
h = h1[h1.keys.first]
|
33
|
+
|
30
34
|
@summary = h[:summary]
|
31
35
|
@records = h[:records]
|
32
36
|
|
@@ -38,6 +42,13 @@ class DxLite
|
|
38
42
|
end
|
39
43
|
|
40
44
|
@schema = @summary[:schema]
|
45
|
+
|
46
|
+
summary_attributes = {
|
47
|
+
recordx_type: 'dynarex',
|
48
|
+
default_key: @schema[/(?<=\()\w+/],
|
49
|
+
}
|
50
|
+
|
51
|
+
@summary.merge!(summary_attributes)
|
41
52
|
|
42
53
|
summary = @summary[:schema][/(?<=\[)[^\]]+/]
|
43
54
|
|
@@ -84,13 +95,29 @@ class DxLite
|
|
84
95
|
def all()
|
85
96
|
|
86
97
|
@records.map do |h|
|
87
|
-
|
98
|
+
|
99
|
+
puts 'h: ' + h.inspect if @debug
|
100
|
+
RecordX.new(h[:body], self, h[:id], h[:created],
|
101
|
+
h[:last_modified])
|
88
102
|
end
|
89
103
|
|
90
104
|
end
|
91
105
|
|
92
|
-
def
|
93
|
-
@records
|
106
|
+
def delete(id)
|
107
|
+
found = @records.find {|x| x[:id] == id}
|
108
|
+
@records.delete found if found
|
109
|
+
end
|
110
|
+
|
111
|
+
def create(h, id: nil, custom_attributes: {created: Time.now})
|
112
|
+
|
113
|
+
id ||= @records.map {|x| x[:id].to_i}.max.to_i + 1
|
114
|
+
h2 = custom_attributes
|
115
|
+
@records << {id: id.to_s, created: h2[:created], last_modified: nil, body: h}
|
116
|
+
end
|
117
|
+
|
118
|
+
def inspect()
|
119
|
+
"#<DxLite:%s @debug=%s, @summary=%s, ...>" % [object_id, @debug,
|
120
|
+
@summary.inspect]
|
94
121
|
end
|
95
122
|
|
96
123
|
# Parses 1 or more lines of text to create or update existing records.
|
@@ -104,7 +131,11 @@ class DxLite
|
|
104
131
|
self.schema = "items/item(%s)" % cols.join(', ')
|
105
132
|
end
|
106
133
|
|
107
|
-
obj.each
|
134
|
+
obj.each do |x|
|
135
|
+
puts 'x: ' + x.inspect if @debug
|
136
|
+
self.create x, id: nil
|
137
|
+
end
|
138
|
+
|
108
139
|
return self
|
109
140
|
|
110
141
|
end
|
@@ -113,13 +144,13 @@ class DxLite
|
|
113
144
|
alias import parse
|
114
145
|
|
115
146
|
def save(file=@filepath)
|
116
|
-
File.write file,
|
147
|
+
File.write file, to_json()
|
117
148
|
end
|
118
149
|
|
119
150
|
alias to_a records
|
120
151
|
|
121
|
-
def
|
122
|
-
|
152
|
+
def to_h()
|
153
|
+
|
123
154
|
root_name = schema()[/^\w+/]
|
124
155
|
record_name = schema()[/(?<=\/)[^\(]+/]
|
125
156
|
|
@@ -130,8 +161,38 @@ class DxLite
|
|
130
161
|
records: @records.map {|h| {record_name.to_sym => h} }
|
131
162
|
}
|
132
163
|
}
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_json(pretty: true)
|
168
|
+
pretty ? JSON.pretty_generate(to_h()) : to_h()
|
169
|
+
end
|
170
|
+
|
171
|
+
def to_xml()
|
172
|
+
|
173
|
+
root_name = schema()[/^\w+/]
|
174
|
+
record_name = schema()[/(?<=\/)[^\(]+/]
|
175
|
+
|
176
|
+
a = RexleBuilder.build do |xml|
|
177
|
+
|
178
|
+
xml.send(root_name.to_sym) do
|
179
|
+
xml.summary({}, @summary)
|
180
|
+
xml.records do
|
181
|
+
|
182
|
+
all().each do |x|
|
183
|
+
|
184
|
+
h = {id: x.id, created: x.created, last_modified: x.last_modified}
|
185
|
+
puts 'x.to_h: ' + x.to_h.inspect if @debug
|
186
|
+
xml.send(record_name.to_sym, h, x.to_h)
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
133
193
|
|
134
|
-
Rexle.new(
|
194
|
+
Rexle.new(a).xml pretty: true
|
195
|
+
|
135
196
|
|
136
197
|
end
|
137
198
|
|
@@ -146,8 +207,8 @@ class DxLite
|
|
146
207
|
puts ('obj.class: ' + obj.class.inspect).debug
|
147
208
|
end
|
148
209
|
|
149
|
-
r = @records.find {|x| x
|
150
|
-
r.merge!(obj)
|
210
|
+
r = @records.find {|x| x[:id] == id}
|
211
|
+
r[:body].merge!(obj)
|
151
212
|
end
|
152
213
|
|
153
214
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -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
|