polyrex 0.8.10 → 0.8.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/polyrex.rb +23 -18
- metadata +2 -2
data/lib/polyrex.rb
CHANGED
@@ -20,7 +20,7 @@ class Polyrex
|
|
20
20
|
|
21
21
|
if location then
|
22
22
|
open(location)
|
23
|
-
summary_h = Hash[*@doc.xpath("summary/*").map {|x| [x.name, x.text]}.flatten]
|
23
|
+
summary_h = Hash[*@doc.root.xpath("summary/*").map {|x| [x.name, x.text]}.flatten]
|
24
24
|
@summary = OpenStruct.new summary_h
|
25
25
|
@summary_fields = summary_h.keys.map(&:to_sym)
|
26
26
|
end
|
@@ -32,12 +32,12 @@ class Polyrex
|
|
32
32
|
# @create is a PolyrexCreateObject, @parent_node is a REXML::Element pointing to the current record
|
33
33
|
|
34
34
|
@create.id = id || @id_counter
|
35
|
-
@create.record = @parent_node.name == 'records' ? @parent_node : @parent_node.element('records')
|
35
|
+
@create.record = @parent_node.name == 'records' ? @parent_node.root : @parent_node.root.element('records')
|
36
36
|
@create
|
37
37
|
end
|
38
38
|
|
39
39
|
def delete(id=nil)
|
40
|
-
@doc.delete("//[@id='#{id}'")
|
40
|
+
@doc.root.delete("//[@id='#{id}'")
|
41
41
|
end
|
42
42
|
|
43
43
|
def record()
|
@@ -59,11 +59,11 @@ class Polyrex
|
|
59
59
|
# -- start of crud methods --
|
60
60
|
|
61
61
|
def find_by_id(id)
|
62
|
-
@parent_node = @doc.element("//[@id='#{id}']")
|
62
|
+
@parent_node = @doc.root.element("//[@id='#{id}']")
|
63
63
|
end
|
64
64
|
|
65
65
|
def id(id)
|
66
|
-
@parent_node = @doc.element("//[@id='#{id}']")
|
66
|
+
@parent_node = @doc.root.element("//[@id='#{id}']")
|
67
67
|
self
|
68
68
|
end
|
69
69
|
|
@@ -81,18 +81,18 @@ class Polyrex
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def element(s)
|
84
|
-
@doc.element(s)
|
84
|
+
@doc.root.element(s)
|
85
85
|
end
|
86
86
|
|
87
87
|
def records
|
88
|
-
@doc.xpath("records/*").map do |record|
|
88
|
+
@doc.root.xpath("records/*").map do |record|
|
89
89
|
@objects_a[0].new(record)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
def schema=(s)
|
94
94
|
open s
|
95
|
-
summary_h = Hash[*@doc.xpath("summary/*").map {|x| [x.name, x.text]}.flatten]
|
95
|
+
summary_h = Hash[*@doc.root.xpath("summary/*").map {|x| [x.name, x.text]}.flatten]
|
96
96
|
@summary = OpenStruct.new summary_h
|
97
97
|
@summary_fields = summary_h.keys.map(&:to_sym)
|
98
98
|
self
|
@@ -114,9 +114,9 @@ class Polyrex
|
|
114
114
|
def xpath(s, &blk)
|
115
115
|
|
116
116
|
if block_given? then
|
117
|
-
@doc.xpath(s, &blk)
|
117
|
+
@doc.root.xpath(s, &blk)
|
118
118
|
else
|
119
|
-
@doc.xpath s
|
119
|
+
@doc.root.xpath s
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -130,7 +130,8 @@ class Polyrex
|
|
130
130
|
def polyrex_new(schema)
|
131
131
|
# -- required for the parsing feature
|
132
132
|
doc = Rexle.new(PolyrexSchema.new(schema).to_s)
|
133
|
-
@format_masks = doc.xpath('//format_mask/text()')
|
133
|
+
@format_masks = doc.root.xpath('//format_mask/text()')
|
134
|
+
#puts '@format_masks : ' + @format_masks.inspect
|
134
135
|
schema_rpath = schema.gsub(/\[[^\]]+\]/,'')
|
135
136
|
|
136
137
|
@recordx = schema_rpath.split('/')
|
@@ -172,6 +173,7 @@ class Polyrex
|
|
172
173
|
end
|
173
174
|
|
174
175
|
def string_parse(lines)
|
176
|
+
|
175
177
|
raw_header = lines.slice!(/<\?polyrex[^>]+>/)
|
176
178
|
|
177
179
|
if raw_header then
|
@@ -182,7 +184,7 @@ class Polyrex
|
|
182
184
|
end
|
183
185
|
end
|
184
186
|
|
185
|
-
format_line!(@parent_node, LineTree.new(lines.strip).to_a)
|
187
|
+
format_line!(@parent_node.root, LineTree.new(lines.strip).to_a)
|
186
188
|
end
|
187
189
|
|
188
190
|
def load_handlers(schema)
|
@@ -209,7 +211,6 @@ class Polyrex
|
|
209
211
|
line = x.shift
|
210
212
|
|
211
213
|
|
212
|
-
|
213
214
|
unless @format_masks[i][/^\(.*\)$/] then
|
214
215
|
|
215
216
|
@field_names = @format_masks[i].to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
|
@@ -241,6 +242,7 @@ class Polyrex
|
|
241
242
|
@id_counter.succ!
|
242
243
|
|
243
244
|
record = Rexle::Element.new(tag_name)
|
245
|
+
|
244
246
|
record.add_attribute(id: @id_counter.clone)
|
245
247
|
summary = Rexle::Element.new('summary')
|
246
248
|
|
@@ -312,7 +314,7 @@ class Polyrex
|
|
312
314
|
@recordx.shift
|
313
315
|
end
|
314
316
|
|
315
|
-
id = @doc.xpath('max(//@id)')
|
317
|
+
id = @doc.root.xpath('max(//@id)')
|
316
318
|
@id_counter = id.to_s.succ if id
|
317
319
|
|
318
320
|
if schema then
|
@@ -320,7 +322,7 @@ class Polyrex
|
|
320
322
|
load_find_by(schema)
|
321
323
|
end
|
322
324
|
|
323
|
-
@parent_node = @doc.element('records')
|
325
|
+
@parent_node = @doc.root.element('records')
|
324
326
|
|
325
327
|
end
|
326
328
|
|
@@ -353,8 +355,11 @@ class Polyrex
|
|
353
355
|
methodx = a.map do |class_name, methods|
|
354
356
|
class_name.downcase!
|
355
357
|
methods.map do |method_name|
|
356
|
-
xpath = %Q(@doc.element("//%s[summary/%s='\#\{val\}']")) % [class_name, method_name]
|
357
|
-
"def find_by_
|
358
|
+
xpath = %Q(@doc.root.element("//%s[summary/%s='\#\{val\}']")) % [class_name, method_name]
|
359
|
+
"def find_by_#{class_name}_#{method_name}(val)
|
360
|
+
@parent_node = #{xpath}
|
361
|
+
@parent_node ? self.#{class_name} : nil
|
362
|
+
end"
|
358
363
|
end
|
359
364
|
end
|
360
365
|
|
@@ -363,7 +368,7 @@ class Polyrex
|
|
363
368
|
|
364
369
|
def refresh_summary()
|
365
370
|
@summary_fields.each do |x|
|
366
|
-
@doc.element('summary/' + x.to_s).text = @summary.method(x).call
|
371
|
+
@doc.root.element('summary/' + x.to_s).text = @summary.method(x).call
|
367
372
|
end
|
368
373
|
end
|
369
374
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: polyrex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.8.
|
5
|
+
version: 0.8.11
|
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: 2011-
|
13
|
+
date: 2011-12-25 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|