dynarex 1.1.40 → 1.2.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.
- data/lib/dynarex.rb +34 -20
- metadata +13 -2
data/lib/dynarex.rb
CHANGED
@@ -12,6 +12,7 @@ require 'dynarex-xslt'
|
|
12
12
|
require 'recordx'
|
13
13
|
require 'rxraw-lineparser'
|
14
14
|
require 'yaml'
|
15
|
+
require 'rowx'
|
15
16
|
|
16
17
|
class Dynarex
|
17
18
|
|
@@ -336,7 +337,8 @@ EOF
|
|
336
337
|
private
|
337
338
|
|
338
339
|
|
339
|
-
def create_find(fields)
|
340
|
+
def create_find(fields)
|
341
|
+
|
340
342
|
methods = fields.map do |field|
|
341
343
|
"def find_by_#{field}(value) findx_by('#{field}', value) end\n" + \
|
342
344
|
"def find_all_by_#{field}(value) findx_all_by('#{field}', value) end"
|
@@ -373,7 +375,7 @@ EOF
|
|
373
375
|
end
|
374
376
|
|
375
377
|
id = (@doc.root.xpath('max(records/*/attribute::id)') || '0').succ unless id
|
376
|
-
|
378
|
+
|
377
379
|
attributes = {id: id, created: Time.now.to_s, last_modified: nil}
|
378
380
|
attributes.each {|k,v| record.add_attribute(k, v)}
|
379
381
|
if @order == 'descending' then
|
@@ -441,28 +443,36 @@ EOF
|
|
441
443
|
@summary[:schema] = @schema
|
442
444
|
@summary[:format_mask] = @format_mask
|
443
445
|
|
444
|
-
|
446
|
+
lines = case raw_lines.first
|
447
|
+
|
448
|
+
when '---'
|
445
449
|
|
446
|
-
|
450
|
+
yaml = YAML.load raw_lines.join("\n")
|
447
451
|
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
452
|
+
yamlize = lambda {|x| (x.is_a? Array) ? x.to_yaml : x}
|
453
|
+
|
454
|
+
yprocs = {
|
455
|
+
Hash: lambda {|y|
|
456
|
+
y.map do |k,v|
|
457
|
+
procs = {Hash: proc {|x| x.values}, Array: proc {v}}
|
458
|
+
values = procs[v.class.to_s.to_sym].call(v).map(&yamlize)
|
459
|
+
[k, *values]
|
460
|
+
end
|
461
|
+
},
|
462
|
+
Array: lambda {|y| y.map {|x2| x2.map(&yamlize)} }
|
463
|
+
}
|
460
464
|
|
461
|
-
|
465
|
+
yprocs[yaml.class.to_s.to_sym].call yaml
|
466
|
+
|
467
|
+
when '--+'
|
468
|
+
|
469
|
+
raw_lines.shift
|
470
|
+
xml = RowX.new(raw_lines.join("\n")).to_xml
|
471
|
+
Rexle.new(xml).root.xpath('item').map{|x| x.xpath('*/text()')}
|
462
472
|
|
463
473
|
else
|
464
474
|
|
465
|
-
|
475
|
+
raw_lines.map do |x|
|
466
476
|
field_names, field_values = RXRawLineParser.new(@format_mask).parse(x)
|
467
477
|
field_values
|
468
478
|
end
|
@@ -555,6 +565,7 @@ EOF
|
|
555
565
|
@schema = @doc.root.text('summary/schema')
|
556
566
|
@root_name = @doc.root.name
|
557
567
|
@summary = summary_to_h
|
568
|
+
|
558
569
|
@order = @summary[:order] if @summary.has_key? :order
|
559
570
|
|
560
571
|
@default_key = @doc.root.element('summary/default_key/text()')
|
@@ -572,7 +583,10 @@ EOF
|
|
572
583
|
# load the record query handler methods
|
573
584
|
attach_record_methods
|
574
585
|
else
|
575
|
-
|
586
|
+
|
587
|
+
#jr080912 @default_key = @doc.root.xpath('records/*/*').first.name
|
588
|
+
|
589
|
+
@default_key = @doc.root.element('records/./.[1]').name
|
576
590
|
end
|
577
591
|
|
578
592
|
if @doc.root.xpath('records/*').length > 0 then
|
@@ -666,4 +680,4 @@ XSL
|
|
666
680
|
end
|
667
681
|
end
|
668
682
|
|
669
|
-
end
|
683
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dynarex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-02 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rexle
|
@@ -100,6 +100,17 @@ dependencies:
|
|
100
100
|
version: "0"
|
101
101
|
type: :runtime
|
102
102
|
version_requirements: *id008
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rowx
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
type: :runtime
|
113
|
+
version_requirements: *id009
|
103
114
|
description:
|
104
115
|
email:
|
105
116
|
executables: []
|