Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

bug fix: selected records from find_by can now be written as well as …

…read
  • Loading branch information...
commit fcb5cdb911b90da2c44b9543cdceb0a30e9bcb5d 1 parent 7d96187
James Robertson authored

Showing 3 changed files with 52 additions and 32 deletions. Show diff stats Hide diff stats

  1. +1 1  dynarex.gemspec
  2. +48 28 lib/dynarex.rb
  3. +3 3 lib/dynarex.rb~
2  dynarex.gemspec
... ... @@ -1,6 +1,6 @@
1 1 Gem::Specification.new do |s|
2 2 s.name = 'dynarex'
3   - s.version = '1.1.16'
  3 + s.version = '1.1.17'
4 4 s.summary = 'dynarex'
5 5 s.authors = ['James Robertson']
6 6 s.files = Dir['lib/**/*.rb']
76 lib/dynarex.rb
@@ -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 @@ def format_mask=(s)
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 @@ def sort_by!(&element_blk)
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 @@ def findx_all_by(field, value)
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 @@ def display_xml(opt={})
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 @@ def attach_record_methods()
460 479 end
461 480
462 481 def open(s)
  482 +
463 483
464 484 if s[/</] then # xml
465 485 buffer = s
6 lib/dynarex.rb~
@@ -383,9 +383,9 @@ EOF
383 383 end
384 384 end
385 385
386   - @summary['recordx_type'] = 'dynarex'
387   - @summary['schema'] = @schema
388   - @summary['format_mask'] = @format_mask
  386 + @summary[:recordx_type] = 'dynarex'
  387 + @summary[:schema] = @schema
  388 + @summary[:format_mask] = @format_mask
389 389
390 390 lines = raw_lines.map {|x|x.strip.match(/#{t}/).captures}
391 391

0 comments on commit fcb5cdb

Please sign in to comment.
Something went wrong with that request. Please try again.