dynarex 1.1.16 → 1.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dynarex.rb +48 -28
  2. metadata +2 -2
@@ -15,6 +15,23 @@ class Dynarex
15
15
 
16
16
  attr_accessor :format_mask, :delimiter, :xslt_schema, :schema
17
17
 
18
+
19
+ class Record
20
+
21
+ def initialize(callerx, id, h={})
22
+
23
+ @callerx, @id = callerx, id
24
+
25
+ methods = h.to_a.map do |k,v|
26
+ name, val = k.to_s, v
27
+ "def #{name}=(s) @#{name} = s.to_s; @callerx.update(@id, #{name}: s.to_s) end\n\
28
+ def #{name}() @#{name} end\n\
29
+ @#{name} = '#{val}'"
30
+ end
31
+ self.instance_eval methods.join("\n")
32
+ end
33
+ end
34
+
18
35
  #Create a new dynarex document from 1 of the following options:
19
36
  #* a local file path
20
37
  #* a URL
@@ -57,7 +74,7 @@ class Dynarex
57
74
  @summary[:format_mask] = @format_mask
58
75
  end
59
76
 
60
- def inspect()
77
+ def inspect2()
61
78
  "<object #%s>" % [self.object_id]
62
79
  end
63
80
 
@@ -223,6 +240,33 @@ EOF
223
240
  load_records
224
241
  self
225
242
  end
243
+
244
+ def rebuild_doc
245
+
246
+ xml = RexleBuilder.new
247
+ a = xml.send @root_name do
248
+ xml.summary do
249
+ @summary.each{|key,value| xml.send key, value}
250
+ end
251
+ if @records then
252
+ xml.records do
253
+
254
+ @records.each do |k, item|
255
+ #p 'foo ' + item.inspect
256
+ xml.send(@record_name, {id: item[:id], created: item[:created], \
257
+ last_modified: item[:last_modified]}, '') do
258
+ item[:body].each{|name,value| xml.send name, value}
259
+ end
260
+ end
261
+
262
+ end
263
+ else
264
+ xml.records
265
+ end # end of if @records
266
+ end
267
+
268
+ @doc = Rexle.new a
269
+ end
226
270
 
227
271
  def record(id)
228
272
  recordx_to_record @doc.root.element("records/*[@id='#{id}']")
@@ -276,7 +320,8 @@ EOF
276
320
  end
277
321
 
278
322
  def recordx_to_record(recordx)
279
- OpenStruct.new(Hash[*@fields.zip(recordx.xpath("*/text()")).flatten])
323
+ Record.new(self, recordx.attributes[:id], \
324
+ Hash[*@fields.zip(recordx.xpath("*/text()")).flatten])
280
325
  end
281
326
 
282
327
  def hash_create(raw_params={}, id=nil)
@@ -318,32 +363,6 @@ EOF
318
363
  @doc.xml(opt) #jr230711 pretty: true
319
364
  end
320
365
 
321
- def rebuild_doc
322
-
323
- xml = RexleBuilder.new
324
- a = xml.send @root_name do
325
- xml.summary do
326
- @summary.each{|key,value| xml.send key, value}
327
- end
328
- if @records then
329
- xml.records do
330
-
331
- @records.each do |k, item|
332
- #p 'foo ' + item.inspect
333
- xml.send(@record_name, {id: item[:id], created: item[:created], \
334
- last_modified: item[:last_modified]}, '') do
335
- item[:body].each{|name,value| xml.send name, value}
336
- end
337
- end
338
-
339
- end
340
- else
341
- xml.records
342
- end # end of if @records
343
- end
344
-
345
- @doc = Rexle.new a
346
- end
347
366
 
348
367
  alias refresh_doc display_xml
349
368
 
@@ -460,6 +479,7 @@ EOF
460
479
  end
461
480
 
462
481
  def open(s)
482
+
463
483
 
464
484
  if s[/</] then # xml
465
485
  buffer = s
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.16
5
+ version: 1.1.17
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-04-09 00:00:00 +01:00
13
+ date: 2012-04-12 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency