polyrex 1.3.2 → 1.3.6

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