polyrex 1.3.0 → 1.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/lib/polyrex.rb +182 -161
- data.tar.gz.sig +0 -0
- metadata +31 -30
- 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: 5e211b56546f7a7d8cc51eff031d5e404ae3d6fc6f7c3082bac158e88fc80f3e
|
4
|
+
data.tar.gz: fde6175c6355d803c5c31f7a49105cbb9ef27ad1b83daf702fcd4a6c144b631f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 821c0da30fb333a44418cf8cbb96789ea9e5e216646d33dee374461db182f54c9df59ba57ac56e2c2050053f31ad829ea8f00ce4d3b0982fd7ca1bac378042bb
|
7
|
+
data.tar.gz: '0785691bdae1f3e99665b1c3600e5ddce7027ef35ecd8eabea1ab98ae02ef33aaf77ceba456a3729be1d6c4ae0e7cb0c0e2bb1865f98ff63da1790dc0a6bf436'
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/polyrex.rb
CHANGED
@@ -39,23 +39,23 @@ class PolyrexException < Exception
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class Polyrex
|
42
|
-
attr_accessor :summary_fields, :xslt_schema, :id_counter,
|
42
|
+
attr_accessor :summary_fields, :xslt_schema, :id_counter,
|
43
43
|
:schema, :type, :delimiter, :xslt, :format_masks
|
44
44
|
|
45
|
-
def initialize(location=nil, schema: nil, id_counter: '1', debug:
|
45
|
+
def initialize(location=nil, schema: nil, id_counter: '1', debug: false)
|
46
46
|
|
47
47
|
|
48
48
|
@id_counter, @debug = id_counter, debug
|
49
49
|
@format_masks = []
|
50
|
-
@delimiter = ''
|
50
|
+
@delimiter = ''
|
51
51
|
|
52
|
-
self.method(:schema=).call(schema) if schema
|
53
|
-
|
54
|
-
if location then
|
52
|
+
self.method(:schema=).call(schema) if schema
|
53
|
+
|
54
|
+
if location then
|
55
55
|
|
56
56
|
s, type = RXFHelper.read(location)
|
57
57
|
return import(s) if s =~ /^\<\?polyrex\b/
|
58
|
-
|
58
|
+
|
59
59
|
@local_filepath = location if type == :file or type == :dfs
|
60
60
|
|
61
61
|
openx(s)
|
@@ -70,10 +70,10 @@ class Polyrex
|
|
70
70
|
|
71
71
|
@summary = RecordX.new @doc.root.xpath("summary/*")
|
72
72
|
@summary_fields = @summary.keys
|
73
|
-
|
73
|
+
|
74
74
|
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
@polyrex_xslt = RecordxXSLT.new
|
78
78
|
#@parent_node = @doc.root if @doc
|
79
79
|
end
|
@@ -99,7 +99,7 @@ class Polyrex
|
|
99
99
|
@doc.root.xpath(x).each(&:delete)
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def delimiter=(separator)
|
104
104
|
|
105
105
|
@delimiter = separator
|
@@ -107,19 +107,23 @@ class Polyrex
|
|
107
107
|
@format_masks.map! do |format_mask|
|
108
108
|
format_mask.to_s.gsub(/\s/, separator)
|
109
109
|
end
|
110
|
-
end
|
111
|
-
|
110
|
+
end
|
111
|
+
|
112
112
|
def each_recursive(parent=self, level=0, &blk)
|
113
|
-
|
113
|
+
|
114
114
|
parent.records.each.with_index do |x, index|
|
115
115
|
|
116
116
|
blk.call(x, parent, level, index) if block_given?
|
117
117
|
|
118
118
|
each_recursive(x, level+1, &blk) if x.records.any?
|
119
|
-
|
119
|
+
|
120
120
|
end
|
121
|
-
|
122
|
-
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def export(filepath)
|
125
|
+
File.write filepath, to_s()
|
126
|
+
end
|
123
127
|
|
124
128
|
def record()
|
125
129
|
@parent_node
|
@@ -130,20 +134,20 @@ class Polyrex
|
|
130
134
|
@doc.to_s(options)
|
131
135
|
end
|
132
136
|
|
133
|
-
def save(filepath=nil, opt={}, options: opt, pretty: false)
|
134
|
-
|
137
|
+
def save(filepath=nil, opt={}, options: opt, pretty: false)
|
138
|
+
|
135
139
|
refresh_summary
|
136
140
|
filepath ||= @local_filepath
|
137
141
|
@local_filepath = filepath
|
138
|
-
|
142
|
+
|
139
143
|
options.merge!({pretty: pretty}) if options.empty?
|
140
144
|
xml = @doc.to_s(options)
|
141
|
-
|
145
|
+
|
142
146
|
buffer = block_given? ? yield(xml) : xml
|
143
|
-
File.open(filepath,'w'){|f| f.write buffer}
|
147
|
+
File.open(filepath,'w'){|f| f.write buffer}
|
144
148
|
end
|
145
|
-
|
146
|
-
# -- start of crud methods --
|
149
|
+
|
150
|
+
# -- start of crud methods --
|
147
151
|
|
148
152
|
def find_by_id(id)
|
149
153
|
@parent_node = @doc.root.element("//[@id='#{id}']")
|
@@ -154,52 +158,52 @@ class Polyrex
|
|
154
158
|
@parent_node = @doc.root.element("//[@id='#{id}']")
|
155
159
|
self
|
156
160
|
end
|
157
|
-
|
161
|
+
|
158
162
|
def order=(val)
|
159
163
|
@order = val.to_s
|
160
164
|
end
|
161
165
|
|
162
166
|
# -- end of crud methods --
|
163
|
-
|
167
|
+
|
164
168
|
# -- start of full text edit methods
|
165
169
|
def format_masks
|
166
170
|
@format_masks
|
167
|
-
end
|
168
|
-
|
171
|
+
end
|
172
|
+
|
169
173
|
def parse(x=nil, options={})
|
170
174
|
|
171
175
|
buffer, type = RXFHelper.read(x)
|
172
|
-
|
176
|
+
|
173
177
|
if type == :unknown and buffer.lines.length <= 1 then
|
174
178
|
raise PolyrexException, 'File not found: ' + x.inspect
|
175
179
|
end
|
176
|
-
|
177
|
-
buffer = yield if block_given?
|
180
|
+
|
181
|
+
buffer = yield if block_given?
|
178
182
|
string_parse buffer.clone, options
|
179
183
|
|
180
184
|
self
|
181
|
-
end
|
182
|
-
|
185
|
+
end
|
186
|
+
|
183
187
|
alias import parse
|
184
188
|
|
185
189
|
def element(s)
|
186
190
|
@doc.root.element(s)
|
187
191
|
end
|
188
|
-
|
192
|
+
|
189
193
|
def leaf_nodes_to_dx()
|
190
|
-
|
194
|
+
|
191
195
|
schema, record_name = @summary.schema\
|
192
196
|
.match(/([^\/]+\/([^\/]+)\[[^\[]+$)/).captures
|
193
|
-
|
197
|
+
|
194
198
|
xml = RexleBuilder.new
|
195
199
|
|
196
200
|
xml.items do
|
197
201
|
xml.summary do
|
198
202
|
xml.schema schema.sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
|
199
203
|
end
|
200
|
-
xml.records
|
204
|
+
xml.records
|
201
205
|
end
|
202
|
-
|
206
|
+
|
203
207
|
doc = Rexle.new xml.to_a
|
204
208
|
body = doc.root.element 'records'
|
205
209
|
a = self.xpath('//' + record_name)
|
@@ -210,43 +214,43 @@ class Polyrex
|
|
210
214
|
|
211
215
|
make_dynarex doc.root
|
212
216
|
end
|
213
|
-
|
217
|
+
|
214
218
|
def records
|
215
219
|
|
216
|
-
@doc.root.xpath("records/*").map do |node|
|
220
|
+
@doc.root.xpath("records/*").map do |node|
|
217
221
|
Kernel.const_get(node.name.capitalize).new node, id: @id_counter
|
218
222
|
end
|
219
|
-
|
223
|
+
|
220
224
|
end
|
221
225
|
|
222
226
|
def rxpath(s)
|
223
|
-
|
227
|
+
|
224
228
|
a = @doc.root.xpath s.split('/').map \
|
225
229
|
{|x| x.sub('[','[summary/').prepend('records/')}.join('/')
|
226
|
-
|
227
|
-
a.map do |node|
|
230
|
+
|
231
|
+
a.map do |node|
|
228
232
|
Kernel.const_get(node.name.capitalize).new node, id: node.attributes[:id]
|
229
233
|
end
|
230
234
|
|
231
235
|
end
|
232
|
-
|
236
|
+
|
233
237
|
def schema=(s)
|
234
238
|
|
235
239
|
if s =~ /gem\[/ then
|
236
|
-
raise PolyrexException, "invalid schema: cannot contain the " +
|
240
|
+
raise PolyrexException, "invalid schema: cannot contain the " +
|
237
241
|
"word gem as a record name"
|
238
242
|
end
|
239
|
-
|
243
|
+
|
240
244
|
openx(s)
|
241
245
|
|
242
246
|
summary_h = Hash[*@doc.root.xpath("summary/*").\
|
243
247
|
map {|x| [x.name, x.text.to_s]}.flatten]
|
244
248
|
|
245
249
|
@summary = RecordX.new summary_h
|
246
|
-
@summary_fields = summary_h.keys.map(&:to_sym)
|
250
|
+
@summary_fields = summary_h.keys.map(&:to_sym)
|
247
251
|
self
|
248
252
|
end
|
249
|
-
|
253
|
+
|
250
254
|
def summary
|
251
255
|
@summary
|
252
256
|
end
|
@@ -254,7 +258,7 @@ class Polyrex
|
|
254
258
|
def to_a()
|
255
259
|
recordx_map @doc.root
|
256
260
|
end
|
257
|
-
|
261
|
+
|
258
262
|
def to_dynarex()
|
259
263
|
|
260
264
|
root = @doc.root.deep_clone
|
@@ -263,17 +267,17 @@ class Polyrex
|
|
263
267
|
#summary.delete('format_mask')
|
264
268
|
#summary.element('recordx_type').text = 'dynarex'
|
265
269
|
|
266
|
-
summary.add root.element('records/*/summary/format_mask').clone
|
270
|
+
summary.add root.element('records/*/summary/format_mask').clone
|
267
271
|
e = summary.element('schema')
|
268
272
|
e.text = e.text[/[^\/]+\/[^\/]+/].sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
|
269
273
|
|
270
274
|
make_dynarex(root)
|
271
275
|
end
|
272
|
-
|
276
|
+
|
273
277
|
def to_opml()
|
274
|
-
|
278
|
+
|
275
279
|
puts '@schema: ' + @schema.inspect if @debug
|
276
|
-
|
280
|
+
|
277
281
|
head, body = @schema.split(/(?<=\])/,2)
|
278
282
|
schema_body = body.gsub(/(?<=\[)[^\]]+/) do |x|
|
279
283
|
x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
|
@@ -284,14 +288,16 @@ class Polyrex
|
|
284
288
|
|
285
289
|
puts 'schema_body: ' + schema_body.inspect if @debug
|
286
290
|
puts 'schema_head: ' + schema_head.inspect if @debug
|
287
|
-
xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
|
288
|
-
|
291
|
+
xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
|
292
|
+
schema_body.gsub(/\w+(?=\[)/,'outline')\
|
293
|
+
.sub(/\/(\w+)(?=\[)/,'/body>outline')
|
294
|
+
|
289
295
|
puts 'xslt_schema: ' + xslt_schema.inspect if @debug
|
290
|
-
|
296
|
+
|
291
297
|
recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
|
292
|
-
|
293
|
-
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
294
|
-
|
298
|
+
|
299
|
+
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
300
|
+
|
295
301
|
end
|
296
302
|
|
297
303
|
def to_s(header: true)
|
@@ -303,11 +309,12 @@ class Polyrex
|
|
303
309
|
summary = item.element 'summary'
|
304
310
|
format_mask = summary.text('format_mask').to_s
|
305
311
|
line = format_mask.gsub(/\[![^\]]+\]/){|x| summary.text(x[2..-2]).to_s}
|
312
|
+
puts 'line: ' + line.inspect if @debug
|
313
|
+
|
314
|
+
recordsx = item.element('records').elements.to_a
|
306
315
|
|
307
|
-
|
308
|
-
|
309
|
-
if records.length > 0 then
|
310
|
-
line = line + "\n" + build(records, indent + 1).join("\n")
|
316
|
+
if recordsx.length > 0 then
|
317
|
+
line = line + "\n" + build(recordsx, indent + 1).join("\n")
|
311
318
|
end
|
312
319
|
(' ' * indent) + line
|
313
320
|
end
|
@@ -327,9 +334,9 @@ class Polyrex
|
|
327
334
|
declaration = @raw_header
|
328
335
|
else
|
329
336
|
|
330
|
-
smry_fields = %i(schema)
|
337
|
+
smry_fields = %i(schema)
|
331
338
|
if self.delimiter.length > 0 then
|
332
|
-
smry_fields << :delimiter
|
339
|
+
smry_fields << :delimiter
|
333
340
|
else
|
334
341
|
smry_fields << :format_mask
|
335
342
|
end
|
@@ -340,13 +347,25 @@ class Polyrex
|
|
340
347
|
declaration = %Q(<?polyrex %s?>\n) % s
|
341
348
|
end
|
342
349
|
|
343
|
-
docheader = declaration + sumry
|
350
|
+
docheader = declaration + "\n" + sumry
|
344
351
|
out = build(self.records).join("\n")
|
345
352
|
header ? docheader + "\n" + out : out
|
346
|
-
|
353
|
+
|
347
354
|
end
|
348
355
|
|
349
|
-
def
|
356
|
+
def to_tree()
|
357
|
+
|
358
|
+
s = @schema.gsub(/(?<=\[)[^\]]+/) do |x|
|
359
|
+
x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
|
360
|
+
end
|
361
|
+
|
362
|
+
xslt_schema = s.gsub(/\w+(?=\[)/,'item').sub(/^\w+/,'tree')
|
363
|
+
recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
|
364
|
+
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
def to_xslt()
|
350
369
|
@polyrex_xslt.schema = @schema
|
351
370
|
@polyrex_xslt.to_xslt
|
352
371
|
end
|
@@ -361,26 +380,26 @@ class Polyrex
|
|
361
380
|
end
|
362
381
|
|
363
382
|
def xslt=(value)
|
364
|
-
|
383
|
+
|
365
384
|
@summary.xslt = value
|
366
385
|
|
367
|
-
end
|
368
|
-
|
386
|
+
end
|
387
|
+
|
369
388
|
def xslt_schema=(s)
|
370
389
|
@polyrex_xslt.xslt_schema = s
|
371
390
|
self
|
372
391
|
end
|
373
|
-
|
392
|
+
|
374
393
|
protected
|
375
|
-
|
394
|
+
|
376
395
|
def doc()
|
377
396
|
@doc
|
378
397
|
end
|
379
398
|
|
380
399
|
private
|
381
|
-
|
400
|
+
|
382
401
|
def make_dynarex(root)
|
383
|
-
|
402
|
+
|
384
403
|
root.delete('summary/recordx_type')
|
385
404
|
root.delete('summary/format_mask')
|
386
405
|
root.xpath('records/*/summary/format_mask').each(&:delete)
|
@@ -414,8 +433,8 @@ xsl_buffer = '
|
|
414
433
|
|
415
434
|
buffer = Rexslt.new(xsl_buffer, root.xml).to_s
|
416
435
|
Dynarex.new buffer
|
417
|
-
|
418
|
-
end
|
436
|
+
|
437
|
+
end
|
419
438
|
|
420
439
|
def refresh_records(records, fields, level)
|
421
440
|
|
@@ -450,10 +469,10 @@ xsl_buffer = '
|
|
450
469
|
flatten.map(&:to_sym)
|
451
470
|
summary = field_names.map {|x| "<%s/>" % x}.join
|
452
471
|
end
|
453
|
-
|
472
|
+
|
454
473
|
summary << "<recordx_type>polyrex</recordx_type><schema>#{schema}</schema>"
|
455
474
|
#----
|
456
|
-
|
475
|
+
|
457
476
|
@schema = schema
|
458
477
|
@id_counter = '0'
|
459
478
|
|
@@ -462,12 +481,12 @@ xsl_buffer = '
|
|
462
481
|
[root_name, (summary || '') , root_name])
|
463
482
|
|
464
483
|
end
|
465
|
-
|
484
|
+
|
466
485
|
def recordx_map(node)
|
467
|
-
|
486
|
+
|
468
487
|
# get the summary
|
469
488
|
fields = node.xpath('summary/*').map do |x|
|
470
|
-
next if %w(schema format_mask recordx_type).include? x.name
|
489
|
+
next if %w(schema format_mask recordx_type).include? x.name
|
471
490
|
r = x.text.to_s.gsub(/^[\n\s]+/,'').length > 0 ? x.text.to_s : \
|
472
491
|
x.cdatas.join.strip
|
473
492
|
r
|
@@ -475,28 +494,28 @@ xsl_buffer = '
|
|
475
494
|
|
476
495
|
# get the records
|
477
496
|
a = node.xpath('records/*').map {|x| recordx_map x}
|
478
|
-
|
497
|
+
|
479
498
|
[fields.compact, a]
|
480
|
-
end
|
481
|
-
|
499
|
+
end
|
500
|
+
|
482
501
|
def string_parse(buffer, options={})
|
483
502
|
|
484
503
|
@raw_header = buffer.slice!(/<\?polyrex[^>]+>/)
|
485
|
-
|
504
|
+
|
486
505
|
if @raw_header then
|
487
506
|
header = @raw_header[/<?polyrex (.*)?>/,1]
|
488
507
|
|
489
508
|
r1 = /([\w\[\]\-]+\s*\=\s*'[^']*)'/
|
490
509
|
r2 = /([\w\[\]\-]+\s*\=\s*"[^"]*)"/
|
491
510
|
|
492
|
-
a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
|
511
|
+
a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
|
512
|
+
|
493
513
|
|
494
|
-
|
495
514
|
a.each do |x|
|
496
|
-
|
515
|
+
|
497
516
|
attr, val = x.split(/\s*=\s*["']/,2)
|
498
517
|
|
499
|
-
i = attr[/format_masks?\[(\d+)/,1]
|
518
|
+
i = attr[/format_masks?\[(\d+)/,1]
|
500
519
|
|
501
520
|
if i then
|
502
521
|
|
@@ -508,28 +527,28 @@ xsl_buffer = '
|
|
508
527
|
end
|
509
528
|
end
|
510
529
|
end
|
511
|
-
|
530
|
+
|
512
531
|
options.each do |k,v|
|
513
|
-
|
532
|
+
|
514
533
|
if options[k] then
|
515
534
|
a.delete a.assoc(k)
|
516
535
|
self.method(((k.to_s) + '=').to_sym).call(options[k])
|
517
536
|
end
|
518
|
-
|
537
|
+
|
519
538
|
end
|
520
|
-
|
539
|
+
|
521
540
|
end
|
522
541
|
|
523
|
-
raw_lines = buffer.
|
542
|
+
raw_lines = buffer.lstrip.lines.map(&:chomp)
|
524
543
|
|
525
544
|
raw_summary = schema[/^\w+\[([^\]]+)/,1]
|
526
545
|
|
527
546
|
if raw_summary then
|
528
547
|
a_summary = raw_summary.split(',').map(&:strip)
|
529
548
|
|
530
|
-
while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
|
549
|
+
while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
|
531
550
|
|
532
|
-
label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
|
551
|
+
label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
|
533
552
|
@summary.send((label + '=').to_sym, val)
|
534
553
|
end
|
535
554
|
|
@@ -541,53 +560,55 @@ xsl_buffer = '
|
|
541
560
|
@parent_node = records.parent
|
542
561
|
records.delete
|
543
562
|
|
544
|
-
|
563
|
+
puts 'raw_lines: ' + raw_lines.inspect if @debug
|
564
|
+
lines = LineTree.new(raw_lines.join("\n"), ignore_label: true).to_a
|
565
|
+
puts 'lines: ' + lines.inspect if @debug
|
545
566
|
@parent_node.root.add format_line!( lines)
|
546
567
|
|
547
|
-
end
|
548
|
-
|
568
|
+
end
|
569
|
+
|
549
570
|
def unescape(s)
|
550
571
|
r = s.gsub('<', '<').gsub('>','>')
|
551
572
|
end
|
552
|
-
|
573
|
+
|
553
574
|
def load_handlers(schema)
|
554
575
|
|
555
|
-
objects = PolyrexObjects.new(schema, debug: @debug)
|
576
|
+
objects = PolyrexObjects.new(schema, debug: @debug)
|
556
577
|
h = objects.to_h
|
557
578
|
puts 'h: ' + h.inspect if @debug
|
558
579
|
@objects = h.inject({}){|r,x| r.merge x[0].downcase => x[-1]}
|
559
580
|
|
560
581
|
@objects_a = objects.to_a
|
561
582
|
attach_create_handlers(@objects.keys)
|
562
|
-
#attach_edit_handlers(@objects)
|
583
|
+
#attach_edit_handlers(@objects)
|
563
584
|
|
564
585
|
end
|
565
|
-
|
586
|
+
|
566
587
|
def format_line!(a, i=0)
|
567
588
|
|
568
589
|
records = Rexle::Element.new('records')
|
569
|
-
|
590
|
+
|
570
591
|
# add code here for rowx
|
571
592
|
@field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
|
572
593
|
.flatten.map(&:to_sym)
|
573
594
|
|
574
595
|
rowx_fields = a.map{|x| x.first[/^\w+(?=:)/].to_s.to_sym}.uniq
|
575
|
-
|
596
|
+
|
576
597
|
records = if (@field_names & rowx_fields).length >= 2 then
|
577
598
|
# rowx implementation still to-do
|
578
599
|
#vertical_fiedlparse(records, a, i)
|
579
600
|
else
|
580
601
|
horizontal_fieldparse(records, a, i)
|
581
602
|
end
|
582
|
-
|
603
|
+
|
583
604
|
end
|
584
|
-
|
585
|
-
|
605
|
+
|
606
|
+
|
586
607
|
# -- end of full text edit methods
|
587
|
-
|
608
|
+
|
588
609
|
def horizontal_fieldparse(records, a, i)
|
589
610
|
|
590
|
-
a.each do |x|
|
611
|
+
a.each do |x|
|
591
612
|
|
592
613
|
unless @recordx[i] then
|
593
614
|
@recordx[i] = @recordx[-1].clone
|
@@ -599,28 +620,28 @@ xsl_buffer = '
|
|
599
620
|
|
600
621
|
|
601
622
|
line = raw_line
|
602
|
-
|
623
|
+
|
603
624
|
if line[/\w+\s*---/] then
|
604
625
|
|
605
626
|
node_name = line.sub(/\s*---/,'')
|
606
627
|
ynode = Rexle::Element.new(node_name).add_text("---\n" + x.join("\n"))
|
607
|
-
|
628
|
+
|
608
629
|
summary.add ynode
|
609
630
|
next
|
610
631
|
end
|
611
|
-
|
632
|
+
|
612
633
|
puts '@schema: ' + @schema.inspect if @debug
|
613
634
|
schema_a = @schema.split('/')[1..-1]
|
614
|
-
|
635
|
+
|
615
636
|
if @debug then
|
616
637
|
puts 'schema_a: ' + schema_a.inspect
|
617
638
|
puts 'i: ' + i.inspect
|
618
639
|
end
|
619
|
-
|
640
|
+
|
620
641
|
unless @format_masks[i][/^\(.*\)$/] then
|
621
642
|
|
622
643
|
@field_names, field_values = RXRawLineParser.new(format_masks[i])\
|
623
|
-
.parse(line)
|
644
|
+
.parse(line)
|
624
645
|
|
625
646
|
@field_names = schema_a[i] ? \
|
626
647
|
schema_a[i][/\[([^\]]+)/,1].split(/\s*,\s*/).map(&:to_sym) : \
|
@@ -635,12 +656,12 @@ xsl_buffer = '
|
|
635
656
|
|
636
657
|
pattern = patterns.detect {|x| line.match(/#{x}/)}
|
637
658
|
i = patterns.index(pattern)
|
638
|
-
|
659
|
+
|
639
660
|
@field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
|
640
661
|
.flatten.map(&:to_sym)
|
641
662
|
|
642
|
-
field_values = line.match(/#{pattern}/).captures
|
643
|
-
|
663
|
+
field_values = line.match(/#{pattern}/).captures
|
664
|
+
|
644
665
|
end
|
645
666
|
|
646
667
|
@id_counter.succ!
|
@@ -650,9 +671,9 @@ xsl_buffer = '
|
|
650
671
|
record.add_attribute(id: @id_counter.clone)
|
651
672
|
summary = Rexle::Element.new('summary')
|
652
673
|
|
653
|
-
@field_names.zip(field_values).each do |name, value|
|
674
|
+
@field_names.zip(field_values).each do |name, value|
|
654
675
|
field = Rexle::Element.new(name.to_s)
|
655
|
-
field.text = value
|
676
|
+
field.text = value
|
656
677
|
summary.add field
|
657
678
|
end
|
658
679
|
|
@@ -664,42 +685,42 @@ xsl_buffer = '
|
|
664
685
|
summary.add Rexle::Element.new('format_mask').add_text(format_mask)
|
665
686
|
summary.add Rexle::Element.new('schema').add_text(schema)
|
666
687
|
summary.add Rexle::Element.new('recordx_type').add_text('polyrex')
|
667
|
-
|
688
|
+
|
668
689
|
record.add summary
|
669
690
|
child_records = format_line!(x, i+1)
|
670
691
|
|
671
692
|
record.add child_records
|
672
693
|
records.add record
|
673
694
|
end
|
674
|
-
|
695
|
+
|
675
696
|
records
|
676
697
|
end
|
677
698
|
|
678
699
|
def attach_create_handlers(names)
|
679
700
|
methodx = names.map do |name|
|
680
701
|
%Q(
|
681
|
-
def create_#{name.downcase}(params, &blk)
|
702
|
+
def create_#{name.downcase}(params, &blk)
|
682
703
|
self.create.#{name.downcase}(params, &blk)
|
683
704
|
end
|
684
705
|
)
|
685
706
|
end
|
686
707
|
|
687
708
|
self.instance_eval(methodx.join("\n"))
|
688
|
-
|
709
|
+
|
689
710
|
end
|
690
|
-
|
711
|
+
|
691
712
|
def attach_edit_handlers(objects)
|
692
713
|
objects.keys.each do |name|
|
693
714
|
self.instance_eval(
|
694
715
|
%Q(
|
695
|
-
def #{name.downcase}()
|
716
|
+
def #{name.downcase}()
|
696
717
|
@objects['#{name}'].new(@parent_node, id: @id)
|
697
718
|
end
|
698
719
|
))
|
699
720
|
end
|
700
|
-
|
721
|
+
|
701
722
|
end
|
702
|
-
|
723
|
+
|
703
724
|
def openx(s)
|
704
725
|
|
705
726
|
if s[/</] # xml
|
@@ -707,7 +728,7 @@ xsl_buffer = '
|
|
707
728
|
elsif s[/\[/] then # schema
|
708
729
|
buffer = polyrex_new s
|
709
730
|
elsif s[/^https?:\/\//] then # url
|
710
|
-
buffer = open(s, 'UserAgent' => 'Polyrex-Reader').read
|
731
|
+
buffer = URI.open(s, 'UserAgent' => 'Polyrex-Reader').read
|
711
732
|
else # local file
|
712
733
|
buffer = File.read s
|
713
734
|
@local_filepath = s
|
@@ -717,9 +738,9 @@ xsl_buffer = '
|
|
717
738
|
@doc = Rexle.new buffer
|
718
739
|
|
719
740
|
schema = @doc.root.text('summary/schema').to_s
|
720
|
-
|
741
|
+
|
721
742
|
if schema.nil? then
|
722
|
-
schema = PolyrexSchema.new.parse(buffer).to_schema
|
743
|
+
schema = PolyrexSchema.new.parse(buffer).to_schema
|
723
744
|
e = @doc.root.element('summary')
|
724
745
|
e.add Rexle::Element.new('schema').add_text(schema)
|
725
746
|
end
|
@@ -742,7 +763,7 @@ xsl_buffer = '
|
|
742
763
|
@parent_node = @doc.root.element('records')
|
743
764
|
|
744
765
|
end
|
745
|
-
|
766
|
+
|
746
767
|
def regexify_fmask(f)
|
747
768
|
|
748
769
|
a = f.split(/(?=\[!\w+\])/).map do |x|
|
@@ -759,45 +780,45 @@ xsl_buffer = '
|
|
759
780
|
end
|
760
781
|
end
|
761
782
|
|
762
|
-
a.join
|
783
|
+
a.join
|
763
784
|
end
|
764
|
-
|
785
|
+
|
765
786
|
def tail_map(a)
|
766
787
|
[a] + (a.length > 1 ? tail_map(a[0..-2]) : [])
|
767
788
|
end
|
768
|
-
|
789
|
+
|
769
790
|
|
770
791
|
def load_find_by(schema)
|
771
792
|
|
772
793
|
a = PolyrexObjectMethods.new(schema).to_a
|
773
794
|
|
774
|
-
methodx = a.map do |class_name, methods|
|
775
|
-
|
795
|
+
methodx = a.map do |class_name, methods|
|
796
|
+
|
776
797
|
class_name.downcase!
|
777
|
-
|
778
|
-
methods.map do |method_name|
|
779
|
-
|
798
|
+
|
799
|
+
methods.map do |method_name|
|
800
|
+
|
780
801
|
xpath = %Q(@doc.root.element("//%s[summary/%s='\#\{val\}']")) % \
|
781
802
|
[class_name, method_name]
|
782
803
|
xpath2 = %Q(@doc.root.xpath("//%s[summary/%s='\#\{val\}']")) % \
|
783
804
|
[class_name, method_name]
|
784
|
-
|
785
|
-
"def find_by_#{class_name}_#{method_name}(val)
|
786
|
-
|
805
|
+
|
806
|
+
"def find_by_#{class_name}_#{method_name}(val)
|
807
|
+
|
787
808
|
node = #{xpath}
|
788
|
-
|
809
|
+
|
789
810
|
if node then
|
790
811
|
Kernel.const_get(node.name.capitalize).new node, id: @id
|
791
812
|
else
|
792
813
|
nil
|
793
814
|
end
|
794
|
-
|
815
|
+
|
795
816
|
end
|
796
817
|
|
797
|
-
def find_all_by_#{class_name}_#{method_name}(val)
|
798
|
-
|
818
|
+
def find_all_by_#{class_name}_#{method_name}(val)
|
819
|
+
|
799
820
|
nodes = #{xpath2}
|
800
|
-
|
821
|
+
|
801
822
|
if nodes then
|
802
823
|
nodes.map do |node|
|
803
824
|
Kernel.const_get(node.name.capitalize).new node, id: @id
|
@@ -805,35 +826,35 @@ xsl_buffer = '
|
|
805
826
|
else
|
806
827
|
nil
|
807
828
|
end
|
808
|
-
|
809
|
-
end
|
829
|
+
|
830
|
+
end
|
810
831
|
"
|
811
|
-
end
|
832
|
+
end
|
812
833
|
end
|
813
834
|
|
814
835
|
self.instance_eval methodx.join("\n")
|
815
836
|
end
|
816
837
|
|
817
838
|
|
818
|
-
# refreshes the XML document with any new modification from
|
839
|
+
# refreshes the XML document with any new modification from
|
819
840
|
# the summary object
|
820
841
|
def refresh_summary()
|
821
|
-
|
822
|
-
summary = @doc.root.element('summary')
|
842
|
+
|
843
|
+
summary = @doc.root.element('summary')
|
823
844
|
@summary.to_h.each do |k,v|
|
824
|
-
|
845
|
+
|
825
846
|
puts "k: %s; v: %s" % [k, v] if @debug
|
826
847
|
e = summary.element(k.to_s)
|
827
848
|
if e then
|
828
849
|
e.text = v
|
829
850
|
else
|
830
|
-
summary.add Rexle::Element.new(k.to_s).add_text(v)
|
851
|
+
summary.add Rexle::Element.new(k.to_s).add_text(v)
|
831
852
|
end
|
832
853
|
end
|
833
|
-
|
854
|
+
|
834
855
|
if @summary.xslt then
|
835
|
-
@doc.instructions = [['xml-stylesheet',
|
836
|
-
"title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
|
856
|
+
@doc.instructions = [['xml-stylesheet',
|
857
|
+
"title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
|
837
858
|
end
|
838
859
|
end
|
839
860
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,31 +11,31 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNTI0MTI1MjMzWhcN
|
15
|
+
MjIwNTI0MTI1MjMzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDxKAjh
|
17
|
+
s6uPs8gcMaoia91NWkBsYkIRp98yXB/MeTcAcK+jM3Y3jbKfbsOa1QVETY+KNZPH
|
18
|
+
byDLynjQE7xOQhZjMrtDB128+iWT+fCvF/OQS0tMMT5ki3qHQDJSqUfxKngwK9p2
|
19
|
+
TlV4EVRaejuPYwGvXxb8qmx9jrR9S3HZVQMHd6aMNAwBb1ZNkSQymWQeEoM+45Un
|
20
|
+
pN3XHGEd2zejUOLNrSiZbBvq5fMb/V2a6LPAfg2WvZzWSZgl4jPjVtvUZVp1BUaU
|
21
|
+
YAXBUsKZ77FC6jR9lb+9iVJAwDTdsI2G6pX5W8EZG0L7i9jeLMQB8bCCzu2zlAhc
|
22
|
+
YJ06owu1LJhPWSxm/3aw6JTKQx0hFepF4mUKHe5iRhDgsVhHNkopzOCQ4JwwHu8G
|
23
|
+
PDi1kUQcFVVkWxRr/m/GRQFkYVn3omgIBMWp/JB8mmevqZ5gaCKvHF55wmDpFzyJ
|
24
|
+
cPDfCtP/wl8wqf363VQdgiru7EcgxQFtPgx6PyMNzfouhRhkBZIY7wYgROkCAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUcuJiQueO
|
26
|
+
q5BdutOcNGPDMgOla5kwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
27
|
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEA1AnaW09JSrJOdlLTeiItH/Mfj6vcAuodI4Ys3PCh
|
29
|
+
UfQsIJUedcMysvo+6J0M+hEYL02w6ynWahcQbzvYPr+NwV/8FqMGGAyDpBSaLtrz
|
30
|
+
9J4cxy4p/mq2dF2lEsCUNoSBWvDpvQI4c2w79/gpWE+w0abHyX97r3N2wWv/OiwV
|
31
|
+
u06GMpESpRj4RAhhy88aDhGDUfMWd+nZ20gWcs2YR1yJf/JyaDfRcOFqLMgVw35Y
|
32
|
+
oQhEZldZrsYsF4FNEBmH2mx2iLq6VbCyZZ3M6jsIHUEDZdrDjbs8ejPvWfEdTW+1
|
33
|
+
x7007qRZCfLvIsqAf7GViMWXgbiv0ZFSKgV7qtK0IgVBg0NDor3xc9w/3VLqshTZ
|
34
|
+
jIqQb9u4Zkhtsp+Ly/HVroN0cylu1t/el2qILTDOkyKnAikvhKpX1wujv+VVqWwd
|
35
|
+
rivEdfkvT/8GV5Nip0lSS+cuk20UhOdJR9QIcCJp0QL4NUik9VYljGbQbQQS6Isc
|
36
|
+
iIwZ6uFJfcp9SWBRrSZmlI52
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: polyrex-objects
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
version: '1.0'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.0.
|
49
|
+
version: 1.0.3
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version: '1.0'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.0.
|
59
|
+
version: 1.0.3
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: polyrex-object-methods
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
version: '1.8'
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.8.
|
109
|
+
version: 1.8.27
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -116,9 +116,9 @@ dependencies:
|
|
116
116
|
version: '1.8'
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: 1.8.
|
119
|
+
version: 1.8.27
|
120
120
|
description:
|
121
|
-
email:
|
121
|
+
email: digital.robertson@gmail.com
|
122
122
|
executables: []
|
123
123
|
extensions: []
|
124
124
|
extra_rdoc_files: []
|
@@ -143,7 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.7.10
|
147
148
|
signing_key:
|
148
149
|
specification_version: 4
|
149
150
|
summary: A flavour of XML for storing and retrieveing records in a Polyrex hierarchy
|
metadata.gz.sig
CHANGED
Binary file
|