polyrex 1.3.3 → 1.4.0

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +3 -1
  3. data/lib/polyrex.rb +170 -167
  4. data.tar.gz.sig +0 -0
  5. metadata +11 -11
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c884051d6c0b1950f1d02849428a0a64cdc9832adcaf780e99bb45821450aa
4
- data.tar.gz: 2b1a471d556dda7ba64a178aeacdf357a7047bfc8f7008bba15c3745b3f7cddb
3
+ metadata.gz: 96b636287f31181cee8839e54a4daa4aaea2028d3f81905bdea129d716cf782d
4
+ data.tar.gz: 29dddede31989032bcd9736513556c76e4714303bf25f1a3005690403a940977
5
5
  SHA512:
6
- metadata.gz: a4c1bbb5c8e1d584c8dd61f65e11244ffd335dbdfcf3f21672667d98cb8926773c4cb55d3496a1e00ca4df2621d7ffcb2b4f1d34fb65164c1ad9051e635035d2
7
- data.tar.gz: 02b2d2878d9c4f99f8000df5db5094bcc29a30d14ea8d8e584b4dc51672d286f6d89cfdeb1913b4b98c6fe3eef46cbe9474843b6a29cec005920f5bc7d5cba8d
6
+ metadata.gz: d49d8b6d854d265d95c260483beb1defc4d210db272e7a8fc6e57ed67bbc08f07ff461bcf96d81c41a248b1a3131f326251e752b01fefdf725b806f57b28403b
7
+ data.tar.gz: 8dfc539223f2c6b331e64086f0e320d6670bea3a3fb1a24ccb9a8963e723b206a7c3630e0628ec6345f5503fc5562509cbcbe7bf389d73deda0c4ece71c62e87
checksums.yaml.gz.sig CHANGED
@@ -1 +1,3 @@
1
- �P��kq�]�%��x`m'i�R�{Kҳ�f)��y���u�����T[��:�uA4���_K-: �OŸ�0��`�2`�1�� oh)w 0��{�\�t���E�=g�c/�����ʧ��@K�*V��M����(m��Au�|D,G���zZFV�К�K��$,z���׳͔�?nEy��.� �_|L����~ ��oB\�4Ɯw����X%�_�#Lu����(�jl�tR>�u;u����qzZ��n4z�hJ��ȿw$�8�ΆD�3)>�@Y�:���ё�m�=~e}ϙ���9{g�j @��*h�=s��0�I�M������E$�㡭p�/��N�d�W��DAب(�Z�h�^�P�`
1
+ }2�x>ؠ-W%��op�{+��;ê��~c��HlS���rG,m q|P�t&�9��5;ԣ��ˮ�<f7n3�Kji�@�_�1��]vA���N��*�
2
+ �깦5��[X�ل�T(�!�<I^�l:����0ckG��I�й�8�ƋhS�
3
+ ���s�S��
data/lib/polyrex.rb CHANGED
@@ -39,27 +39,28 @@ class PolyrexException < Exception
39
39
  end
40
40
 
41
41
  class Polyrex
42
- attr_accessor :summary_fields, :xslt_schema, :id_counter,
42
+ include RXFReadWriteModule
43
+
44
+ attr_accessor :summary_fields, :xslt_schema, :id_counter,
43
45
  :schema, :type, :delimiter, :xslt, :format_masks
44
46
 
45
47
  def initialize(location=nil, schema: nil, id_counter: '1', debug: false)
46
48
 
47
-
48
49
  @id_counter, @debug = id_counter, debug
49
50
  @format_masks = []
50
- @delimiter = ''
51
+ @delimiter = ''
51
52
 
52
- self.method(:schema=).call(schema) if schema
53
-
54
- if location then
53
+ self.method(:schema=).call(schema) if schema
55
54
 
56
- s, type = RXFHelper.read(location)
55
+ if location then
56
+
57
+ s, type = RXFReader.read(location)
57
58
  return import(s) if s =~ /^\<\?polyrex\b/
58
-
59
+
59
60
  @local_filepath = location if type == :file or type == :dfs
60
61
 
61
62
  openx(s)
62
-
63
+ puts 'before schema' if @debug
63
64
  if schema then
64
65
 
65
66
  fields = @schema[/\/.*/].scan(/\[([^\]]+)/).map \
@@ -70,10 +71,10 @@ class Polyrex
70
71
 
71
72
  @summary = RecordX.new @doc.root.xpath("summary/*")
72
73
  @summary_fields = @summary.keys
73
-
74
+
74
75
 
75
76
  end
76
-
77
+
77
78
  @polyrex_xslt = RecordxXSLT.new
78
79
  #@parent_node = @doc.root if @doc
79
80
  end
@@ -99,7 +100,7 @@ class Polyrex
99
100
  @doc.root.xpath(x).each(&:delete)
100
101
  end
101
102
  end
102
-
103
+
103
104
  def delimiter=(separator)
104
105
 
105
106
  @delimiter = separator
@@ -107,22 +108,22 @@ class Polyrex
107
108
  @format_masks.map! do |format_mask|
108
109
  format_mask.to_s.gsub(/\s/, separator)
109
110
  end
110
- end
111
-
111
+ end
112
+
112
113
  def each_recursive(parent=self, level=0, &blk)
113
-
114
+
114
115
  parent.records.each.with_index do |x, index|
115
116
 
116
117
  blk.call(x, parent, level, index) if block_given?
117
118
 
118
119
  each_recursive(x, level+1, &blk) if x.records.any?
119
-
120
+
120
121
  end
121
-
122
+
122
123
  end
123
124
 
124
125
  def export(filepath)
125
- File.write filepath, to_s()
126
+ FileX.write filepath, to_s()
126
127
  end
127
128
 
128
129
  def record()
@@ -134,20 +135,20 @@ class Polyrex
134
135
  @doc.to_s(options)
135
136
  end
136
137
 
137
- def save(filepath=nil, opt={}, options: opt, pretty: false)
138
-
138
+ def save(filepath=nil, opt={}, options: opt, pretty: false)
139
+
139
140
  refresh_summary
140
141
  filepath ||= @local_filepath
141
142
  @local_filepath = filepath
142
-
143
+
143
144
  options.merge!({pretty: pretty}) if options.empty?
144
145
  xml = @doc.to_s(options)
145
-
146
+
146
147
  buffer = block_given? ? yield(xml) : xml
147
- File.open(filepath,'w'){|f| f.write buffer}
148
+ FileX.write filepath, buffer
148
149
  end
149
-
150
- # -- start of crud methods --
150
+
151
+ # -- start of crud methods --
151
152
 
152
153
  def find_by_id(id)
153
154
  @parent_node = @doc.root.element("//[@id='#{id}']")
@@ -158,52 +159,52 @@ class Polyrex
158
159
  @parent_node = @doc.root.element("//[@id='#{id}']")
159
160
  self
160
161
  end
161
-
162
+
162
163
  def order=(val)
163
164
  @order = val.to_s
164
165
  end
165
166
 
166
167
  # -- end of crud methods --
167
-
168
+
168
169
  # -- start of full text edit methods
169
170
  def format_masks
170
171
  @format_masks
171
- end
172
-
172
+ end
173
+
173
174
  def parse(x=nil, options={})
174
175
 
175
- buffer, type = RXFHelper.read(x)
176
-
176
+ buffer, type = RXFReader.read(x)
177
+
177
178
  if type == :unknown and buffer.lines.length <= 1 then
178
179
  raise PolyrexException, 'File not found: ' + x.inspect
179
180
  end
180
-
181
- buffer = yield if block_given?
181
+
182
+ buffer = yield if block_given?
182
183
  string_parse buffer.clone, options
183
184
 
184
185
  self
185
- end
186
-
186
+ end
187
+
187
188
  alias import parse
188
189
 
189
190
  def element(s)
190
191
  @doc.root.element(s)
191
192
  end
192
-
193
+
193
194
  def leaf_nodes_to_dx()
194
-
195
+
195
196
  schema, record_name = @summary.schema\
196
197
  .match(/([^\/]+\/([^\/]+)\[[^\[]+$)/).captures
197
-
198
+
198
199
  xml = RexleBuilder.new
199
200
 
200
201
  xml.items do
201
202
  xml.summary do
202
203
  xml.schema schema.sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
203
204
  end
204
- xml.records
205
+ xml.records
205
206
  end
206
-
207
+
207
208
  doc = Rexle.new xml.to_a
208
209
  body = doc.root.element 'records'
209
210
  a = self.xpath('//' + record_name)
@@ -214,43 +215,43 @@ class Polyrex
214
215
 
215
216
  make_dynarex doc.root
216
217
  end
217
-
218
+
218
219
  def records
219
220
 
220
- @doc.root.xpath("records/*").map do |node|
221
+ @doc.root.xpath("records/*").map do |node|
221
222
  Kernel.const_get(node.name.capitalize).new node, id: @id_counter
222
223
  end
223
-
224
+
224
225
  end
225
226
 
226
227
  def rxpath(s)
227
-
228
+
228
229
  a = @doc.root.xpath s.split('/').map \
229
230
  {|x| x.sub('[','[summary/').prepend('records/')}.join('/')
230
-
231
- a.map do |node|
231
+
232
+ a.map do |node|
232
233
  Kernel.const_get(node.name.capitalize).new node, id: node.attributes[:id]
233
234
  end
234
235
 
235
236
  end
236
-
237
+
237
238
  def schema=(s)
238
239
 
239
240
  if s =~ /gem\[/ then
240
- raise PolyrexException, "invalid schema: cannot contain the " +
241
+ raise PolyrexException, "invalid schema: cannot contain the " +
241
242
  "word gem as a record name"
242
243
  end
243
-
244
+
244
245
  openx(s)
245
246
 
246
247
  summary_h = Hash[*@doc.root.xpath("summary/*").\
247
248
  map {|x| [x.name, x.text.to_s]}.flatten]
248
249
 
249
250
  @summary = RecordX.new summary_h
250
- @summary_fields = summary_h.keys.map(&:to_sym)
251
+ @summary_fields = summary_h.keys.map(&:to_sym)
251
252
  self
252
253
  end
253
-
254
+
254
255
  def summary
255
256
  @summary
256
257
  end
@@ -258,7 +259,7 @@ class Polyrex
258
259
  def to_a()
259
260
  recordx_map @doc.root
260
261
  end
261
-
262
+
262
263
  def to_dynarex()
263
264
 
264
265
  root = @doc.root.deep_clone
@@ -267,17 +268,17 @@ class Polyrex
267
268
  #summary.delete('format_mask')
268
269
  #summary.element('recordx_type').text = 'dynarex'
269
270
 
270
- summary.add root.element('records/*/summary/format_mask').clone
271
+ summary.add root.element('records/*/summary/format_mask').clone
271
272
  e = summary.element('schema')
272
273
  e.text = e.text[/[^\/]+\/[^\/]+/].sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
273
274
 
274
275
  make_dynarex(root)
275
276
  end
276
-
277
+
277
278
  def to_opml()
278
-
279
+
279
280
  puts '@schema: ' + @schema.inspect if @debug
280
-
281
+
281
282
  head, body = @schema.split(/(?<=\])/,2)
282
283
  schema_body = body.gsub(/(?<=\[)[^\]]+/) do |x|
283
284
  x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
@@ -288,16 +289,16 @@ class Polyrex
288
289
 
289
290
  puts 'schema_body: ' + schema_body.inspect if @debug
290
291
  puts 'schema_head: ' + schema_head.inspect if @debug
291
- xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
292
+ xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
292
293
  schema_body.gsub(/\w+(?=\[)/,'outline')\
293
294
  .sub(/\/(\w+)(?=\[)/,'/body>outline')
294
-
295
+
295
296
  puts 'xslt_schema: ' + xslt_schema.inspect if @debug
296
-
297
+
297
298
  recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
298
-
299
- Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
300
-
299
+
300
+ Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
301
+
301
302
  end
302
303
 
303
304
  def to_s(header: true)
@@ -312,9 +313,9 @@ class Polyrex
312
313
  puts 'line: ' + line.inspect if @debug
313
314
 
314
315
  recordsx = item.element('records').elements.to_a
315
-
316
+
316
317
  if recordsx.length > 0 then
317
- line = line + "\n" + build(recordsx, indent + 1).join("\n")
318
+ line = line + "\n" + build(recordsx, indent + 1).join("\n")
318
319
  end
319
320
  (' ' * indent) + line
320
321
  end
@@ -334,9 +335,9 @@ class Polyrex
334
335
  declaration = @raw_header
335
336
  else
336
337
 
337
- smry_fields = %i(schema)
338
+ smry_fields = %i(schema)
338
339
  if self.delimiter.length > 0 then
339
- smry_fields << :delimiter
340
+ smry_fields << :delimiter
340
341
  else
341
342
  smry_fields << :format_mask
342
343
  end
@@ -350,22 +351,22 @@ class Polyrex
350
351
  docheader = declaration + "\n" + sumry
351
352
  out = build(self.records).join("\n")
352
353
  header ? docheader + "\n" + out : out
353
-
354
+
354
355
  end
355
-
356
+
356
357
  def to_tree()
357
-
358
+
358
359
  s = @schema.gsub(/(?<=\[)[^\]]+/) do |x|
359
360
  x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
360
361
  end
361
362
 
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
363
+ xslt_schema = s.gsub(/\w+(?=\[)/,'item').sub(/^\w+/,'tree')
364
+ recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
365
+ Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
367
366
 
368
- def to_xslt()
367
+ end
368
+
369
+ def to_xslt()
369
370
  @polyrex_xslt.schema = @schema
370
371
  @polyrex_xslt.to_xslt
371
372
  end
@@ -380,26 +381,26 @@ class Polyrex
380
381
  end
381
382
 
382
383
  def xslt=(value)
383
-
384
+
384
385
  @summary.xslt = value
385
386
 
386
- end
387
-
387
+ end
388
+
388
389
  def xslt_schema=(s)
389
390
  @polyrex_xslt.xslt_schema = s
390
391
  self
391
392
  end
392
-
393
+
393
394
  protected
394
-
395
+
395
396
  def doc()
396
397
  @doc
397
398
  end
398
399
 
399
400
  private
400
-
401
+
401
402
  def make_dynarex(root)
402
-
403
+
403
404
  root.delete('summary/recordx_type')
404
405
  root.delete('summary/format_mask')
405
406
  root.xpath('records/*/summary/format_mask').each(&:delete)
@@ -433,8 +434,8 @@ xsl_buffer = '
433
434
 
434
435
  buffer = Rexslt.new(xsl_buffer, root.xml).to_s
435
436
  Dynarex.new buffer
436
-
437
- end
437
+
438
+ end
438
439
 
439
440
  def refresh_records(records, fields, level)
440
441
 
@@ -469,10 +470,10 @@ xsl_buffer = '
469
470
  flatten.map(&:to_sym)
470
471
  summary = field_names.map {|x| "<%s/>" % x}.join
471
472
  end
472
-
473
+
473
474
  summary << "<recordx_type>polyrex</recordx_type><schema>#{schema}</schema>"
474
475
  #----
475
-
476
+
476
477
  @schema = schema
477
478
  @id_counter = '0'
478
479
 
@@ -481,12 +482,12 @@ xsl_buffer = '
481
482
  [root_name, (summary || '') , root_name])
482
483
 
483
484
  end
484
-
485
+
485
486
  def recordx_map(node)
486
-
487
+
487
488
  # get the summary
488
489
  fields = node.xpath('summary/*').map do |x|
489
- next if %w(schema format_mask recordx_type).include? x.name
490
+ next if %w(schema format_mask recordx_type).include? x.name
490
491
  r = x.text.to_s.gsub(/^[\n\s]+/,'').length > 0 ? x.text.to_s : \
491
492
  x.cdatas.join.strip
492
493
  r
@@ -494,28 +495,28 @@ xsl_buffer = '
494
495
 
495
496
  # get the records
496
497
  a = node.xpath('records/*').map {|x| recordx_map x}
497
-
498
+
498
499
  [fields.compact, a]
499
- end
500
-
500
+ end
501
+
501
502
  def string_parse(buffer, options={})
502
503
 
503
504
  @raw_header = buffer.slice!(/<\?polyrex[^>]+>/)
504
-
505
+
505
506
  if @raw_header then
506
507
  header = @raw_header[/<?polyrex (.*)?>/,1]
507
508
 
508
509
  r1 = /([\w\[\]\-]+\s*\=\s*'[^']*)'/
509
510
  r2 = /([\w\[\]\-]+\s*\=\s*"[^"]*)"/
510
511
 
511
- a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
512
+ a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
513
+
512
514
 
513
-
514
515
  a.each do |x|
515
-
516
+
516
517
  attr, val = x.split(/\s*=\s*["']/,2)
517
518
 
518
- i = attr[/format_masks?\[(\d+)/,1]
519
+ i = attr[/format_masks?\[(\d+)/,1]
519
520
 
520
521
  if i then
521
522
 
@@ -527,16 +528,16 @@ xsl_buffer = '
527
528
  end
528
529
  end
529
530
  end
530
-
531
+
531
532
  options.each do |k,v|
532
-
533
+
533
534
  if options[k] then
534
535
  a.delete a.assoc(k)
535
536
  self.method(((k.to_s) + '=').to_sym).call(options[k])
536
537
  end
537
-
538
+
538
539
  end
539
-
540
+
540
541
  end
541
542
 
542
543
  raw_lines = buffer.lstrip.lines.map(&:chomp)
@@ -546,9 +547,9 @@ xsl_buffer = '
546
547
  if raw_summary then
547
548
  a_summary = raw_summary.split(',').map(&:strip)
548
549
 
549
- while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
550
+ while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
550
551
 
551
- label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
552
+ label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
552
553
  @summary.send((label + '=').to_sym, val)
553
554
  end
554
555
 
@@ -565,50 +566,50 @@ xsl_buffer = '
565
566
  puts 'lines: ' + lines.inspect if @debug
566
567
  @parent_node.root.add format_line!( lines)
567
568
 
568
- end
569
-
569
+ end
570
+
570
571
  def unescape(s)
571
572
  r = s.gsub('&lt;', '<').gsub('&gt;','>')
572
573
  end
573
-
574
+
574
575
  def load_handlers(schema)
575
576
 
576
- objects = PolyrexObjects.new(schema, debug: @debug)
577
+ objects = PolyrexObjects.new(schema, debug: @debug)
577
578
  h = objects.to_h
578
579
  puts 'h: ' + h.inspect if @debug
579
580
  @objects = h.inject({}){|r,x| r.merge x[0].downcase => x[-1]}
580
581
 
581
582
  @objects_a = objects.to_a
582
583
  attach_create_handlers(@objects.keys)
583
- #attach_edit_handlers(@objects)
584
+ #attach_edit_handlers(@objects)
584
585
 
585
586
  end
586
-
587
+
587
588
  def format_line!(a, i=0)
588
589
 
589
590
  records = Rexle::Element.new('records')
590
-
591
+
591
592
  # add code here for rowx
592
593
  @field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
593
594
  .flatten.map(&:to_sym)
594
595
 
595
596
  rowx_fields = a.map{|x| x.first[/^\w+(?=:)/].to_s.to_sym}.uniq
596
-
597
+
597
598
  records = if (@field_names & rowx_fields).length >= 2 then
598
599
  # rowx implementation still to-do
599
600
  #vertical_fiedlparse(records, a, i)
600
601
  else
601
602
  horizontal_fieldparse(records, a, i)
602
603
  end
603
-
604
+
604
605
  end
605
-
606
-
606
+
607
+
607
608
  # -- end of full text edit methods
608
-
609
+
609
610
  def horizontal_fieldparse(records, a, i)
610
611
 
611
- a.each do |x|
612
+ a.each do |x|
612
613
 
613
614
  unless @recordx[i] then
614
615
  @recordx[i] = @recordx[-1].clone
@@ -620,28 +621,28 @@ xsl_buffer = '
620
621
 
621
622
 
622
623
  line = raw_line
623
-
624
+
624
625
  if line[/\w+\s*---/] then
625
626
 
626
627
  node_name = line.sub(/\s*---/,'')
627
628
  ynode = Rexle::Element.new(node_name).add_text("---\n" + x.join("\n"))
628
-
629
+
629
630
  summary.add ynode
630
631
  next
631
632
  end
632
-
633
+
633
634
  puts '@schema: ' + @schema.inspect if @debug
634
635
  schema_a = @schema.split('/')[1..-1]
635
-
636
+
636
637
  if @debug then
637
638
  puts 'schema_a: ' + schema_a.inspect
638
639
  puts 'i: ' + i.inspect
639
640
  end
640
-
641
+
641
642
  unless @format_masks[i][/^\(.*\)$/] then
642
643
 
643
644
  @field_names, field_values = RXRawLineParser.new(format_masks[i])\
644
- .parse(line)
645
+ .parse(line)
645
646
 
646
647
  @field_names = schema_a[i] ? \
647
648
  schema_a[i][/\[([^\]]+)/,1].split(/\s*,\s*/).map(&:to_sym) : \
@@ -656,12 +657,12 @@ xsl_buffer = '
656
657
 
657
658
  pattern = patterns.detect {|x| line.match(/#{x}/)}
658
659
  i = patterns.index(pattern)
659
-
660
+
660
661
  @field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
661
662
  .flatten.map(&:to_sym)
662
663
 
663
- field_values = line.match(/#{pattern}/).captures
664
-
664
+ field_values = line.match(/#{pattern}/).captures
665
+
665
666
  end
666
667
 
667
668
  @id_counter.succ!
@@ -671,9 +672,9 @@ xsl_buffer = '
671
672
  record.add_attribute(id: @id_counter.clone)
672
673
  summary = Rexle::Element.new('summary')
673
674
 
674
- @field_names.zip(field_values).each do |name, value|
675
+ @field_names.zip(field_values).each do |name, value|
675
676
  field = Rexle::Element.new(name.to_s)
676
- field.text = value
677
+ field.text = value
677
678
  summary.add field
678
679
  end
679
680
 
@@ -685,52 +686,54 @@ xsl_buffer = '
685
686
  summary.add Rexle::Element.new('format_mask').add_text(format_mask)
686
687
  summary.add Rexle::Element.new('schema').add_text(schema)
687
688
  summary.add Rexle::Element.new('recordx_type').add_text('polyrex')
688
-
689
+
689
690
  record.add summary
690
691
  child_records = format_line!(x, i+1)
691
692
 
692
693
  record.add child_records
693
694
  records.add record
694
695
  end
695
-
696
+
696
697
  records
697
698
  end
698
699
 
699
700
  def attach_create_handlers(names)
700
701
  methodx = names.map do |name|
701
702
  %Q(
702
- def create_#{name.downcase}(params, &blk)
703
+ def create_#{name.downcase}(params, &blk)
703
704
  self.create.#{name.downcase}(params, &blk)
704
705
  end
705
706
  )
706
707
  end
707
708
 
708
709
  self.instance_eval(methodx.join("\n"))
709
-
710
+
710
711
  end
711
-
712
+
712
713
  def attach_edit_handlers(objects)
713
714
  objects.keys.each do |name|
714
715
  self.instance_eval(
715
716
  %Q(
716
- def #{name.downcase}()
717
+ def #{name.downcase}()
717
718
  @objects['#{name}'].new(@parent_node, id: @id)
718
719
  end
719
720
  ))
720
721
  end
721
-
722
+
722
723
  end
723
-
724
+
724
725
  def openx(s)
725
726
 
727
+ puts 'inside openx' if @debug
728
+
726
729
  if s[/</] # xml
727
730
  buffer = s
728
731
  elsif s[/\[/] then # schema
729
732
  buffer = polyrex_new s
730
733
  elsif s[/^https?:\/\//] then # url
731
- buffer = open(s, 'UserAgent' => 'Polyrex-Reader').read
734
+ buffer = URI.open(s, 'UserAgent' => 'Polyrex-Reader').read
732
735
  else # local file
733
- buffer = File.read s
736
+ buffer = FileX.read s
734
737
  @local_filepath = s
735
738
  end
736
739
 
@@ -738,9 +741,9 @@ xsl_buffer = '
738
741
  @doc = Rexle.new buffer
739
742
 
740
743
  schema = @doc.root.text('summary/schema').to_s
741
-
744
+
742
745
  if schema.nil? then
743
- schema = PolyrexSchema.new.parse(buffer).to_schema
746
+ schema = PolyrexSchema.new.parse(buffer).to_schema
744
747
  e = @doc.root.element('summary')
745
748
  e.add Rexle::Element.new('schema').add_text(schema)
746
749
  end
@@ -763,7 +766,7 @@ xsl_buffer = '
763
766
  @parent_node = @doc.root.element('records')
764
767
 
765
768
  end
766
-
769
+
767
770
  def regexify_fmask(f)
768
771
 
769
772
  a = f.split(/(?=\[!\w+\])/).map do |x|
@@ -780,45 +783,45 @@ xsl_buffer = '
780
783
  end
781
784
  end
782
785
 
783
- a.join
786
+ a.join
784
787
  end
785
-
788
+
786
789
  def tail_map(a)
787
790
  [a] + (a.length > 1 ? tail_map(a[0..-2]) : [])
788
791
  end
789
-
792
+
790
793
 
791
794
  def load_find_by(schema)
792
795
 
793
796
  a = PolyrexObjectMethods.new(schema).to_a
794
797
 
795
- methodx = a.map do |class_name, methods|
796
-
798
+ methodx = a.map do |class_name, methods|
799
+
797
800
  class_name.downcase!
798
-
799
- methods.map do |method_name|
800
-
801
+
802
+ methods.map do |method_name|
803
+
801
804
  xpath = %Q(@doc.root.element("//%s[summary/%s='\#\{val\}']")) % \
802
805
  [class_name, method_name]
803
806
  xpath2 = %Q(@doc.root.xpath("//%s[summary/%s='\#\{val\}']")) % \
804
807
  [class_name, method_name]
805
-
806
- "def find_by_#{class_name}_#{method_name}(val)
807
-
808
+
809
+ "def find_by_#{class_name}_#{method_name}(val)
810
+
808
811
  node = #{xpath}
809
-
812
+
810
813
  if node then
811
814
  Kernel.const_get(node.name.capitalize).new node, id: @id
812
815
  else
813
816
  nil
814
817
  end
815
-
818
+
816
819
  end
817
820
 
818
- def find_all_by_#{class_name}_#{method_name}(val)
819
-
821
+ def find_all_by_#{class_name}_#{method_name}(val)
822
+
820
823
  nodes = #{xpath2}
821
-
824
+
822
825
  if nodes then
823
826
  nodes.map do |node|
824
827
  Kernel.const_get(node.name.capitalize).new node, id: @id
@@ -826,35 +829,35 @@ xsl_buffer = '
826
829
  else
827
830
  nil
828
831
  end
829
-
830
- end
832
+
833
+ end
831
834
  "
832
- end
835
+ end
833
836
  end
834
837
 
835
838
  self.instance_eval methodx.join("\n")
836
839
  end
837
840
 
838
841
 
839
- # refreshes the XML document with any new modification from
842
+ # refreshes the XML document with any new modification from
840
843
  # the summary object
841
844
  def refresh_summary()
842
-
843
- summary = @doc.root.element('summary')
845
+
846
+ summary = @doc.root.element('summary')
844
847
  @summary.to_h.each do |k,v|
845
-
848
+
846
849
  puts "k: %s; v: %s" % [k, v] if @debug
847
850
  e = summary.element(k.to_s)
848
851
  if e then
849
852
  e.text = v
850
853
  else
851
- summary.add Rexle::Element.new(k.to_s).add_text(v)
854
+ summary.add Rexle::Element.new(k.to_s).add_text(v)
852
855
  end
853
856
  end
854
-
857
+
855
858
  if @summary.xslt then
856
- @doc.instructions = [['xml-stylesheet',
857
- "title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
859
+ @doc.instructions = [['xml-stylesheet',
860
+ "title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
858
861
  end
859
862
  end
860
863
 
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.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  rivEdfkvT/8GV5Nip0lSS+cuk20UhOdJR9QIcCJp0QL4NUik9VYljGbQbQQS6Isc
36
36
  iIwZ6uFJfcp9SWBRrSZmlI52
37
37
  -----END CERTIFICATE-----
38
- date: 2021-06-05 00:00:00.000000000 Z
38
+ date: 2022-02-21 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.1
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.1
59
+ version: 1.0.3
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: polyrex-object-methods
62
62
  requirement: !ruby/object:Gem::Requirement
@@ -103,22 +103,22 @@ dependencies:
103
103
  requirements:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: '1.8'
106
+ version: '1.9'
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 1.8.19
109
+ version: 1.9.5
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '1.8'
116
+ version: '1.9'
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 1.8.19
119
+ version: 1.9.5
120
120
  description:
121
- email: james@jamesrobertson.eu
121
+ email: digital.robertson@gmail.com
122
122
  executables: []
123
123
  extensions: []
124
124
  extra_rdoc_files: []
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.1.2
146
+ rubygems_version: 3.2.22
147
147
  signing_key:
148
148
  specification_version: 4
149
- summary: A flavour of XML for storing and retrieveing records in a Polyrex hierarchy
149
+ summary: A flavour of XML for storing and retrieving records in a Polyrex hierarchy
150
150
  test_files: []
metadata.gz.sig CHANGED
Binary file