dynarex 1.1.27 → 1.1.28

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 +21 -11
  2. metadata +2 -2
@@ -26,8 +26,9 @@ class Dynarex
26
26
  # Dynarex.new '<contacts><summary><schema>contacts/contact(name,age,dob)</schema></summary><records/></contacts>'
27
27
 
28
28
  def initialize(location=nil)
29
- @delimiter = ' '
29
+ @delimiter = ' '
30
30
  open(location) if location
31
+ @dirty_flag = false
31
32
  end
32
33
 
33
34
  def add(x)
@@ -76,11 +77,13 @@ class Dynarex
76
77
  #Return a Hash (which can be edited) containing all records.
77
78
 
78
79
  def records
80
+ load_records if @dirty_flag == true
79
81
  @records
80
82
  end
81
83
 
82
84
  #Returns a ready-only snapshot of records as a simple Hash.
83
85
  def flat_records
86
+ load_records if @dirty_flag == true
84
87
  @flat_records
85
88
  end
86
89
 
@@ -151,11 +154,12 @@ EOF
151
154
 
152
155
  def create(arg, id=nil)
153
156
 
154
- rebuild_doc()
157
+ #jr190512 rebuild_doc()
155
158
  methods = {Hash: :hash_create, String: :create_from_line}
156
159
  send (methods[arg.class.to_s.to_sym]), arg, id
157
160
 
158
- load_records
161
+ #jr190512 load_records
162
+ @dirty_flag = true
159
163
  self
160
164
  end
161
165
 
@@ -185,7 +189,7 @@ EOF
185
189
  fields.each {|k,v| record.element(k.to_s).text = v if v}
186
190
  record.add_attribute(last_modified: Time.now.to_s)
187
191
 
188
- load_records
192
+ @dirty_flag = true
189
193
 
190
194
  self
191
195
 
@@ -202,7 +206,7 @@ EOF
202
206
  else
203
207
  @doc.delete x
204
208
  end
205
- load_records
209
+ @dirty_flag = true
206
210
  self
207
211
  end
208
212
 
@@ -246,7 +250,8 @@ EOF
246
250
  xml.send(@record_name, {id: item[:id], created: item[:created], \
247
251
  last_modified: item[:last_modified]}, '') do
248
252
  item[:body].each do |name,value|
249
- name = name.to_s.prepend('._').to_sym if reserved_keywords.include? name
253
+ #name = name.to_s.prepend('._').to_sym if reserved_keywords.include? name
254
+ name = ('._' + name.to_s).to_sym if reserved_keywords.include? name
250
255
  xml.send name, value
251
256
  end
252
257
  end
@@ -257,7 +262,7 @@ EOF
257
262
  xml.records
258
263
  end # end of if @records
259
264
  end
260
-
265
+ #puts 'a : ' + a.inspect
261
266
  @doc = Rexle.new a
262
267
  end
263
268
 
@@ -284,8 +289,10 @@ EOF
284
289
  return xslt
285
290
  end
286
291
 
287
- def to_rss(opt={}, summary={})
288
- doc = Rexle.new('<rss version="2.0">' + self.to_xslt(opt) + '</rss>')
292
+ def to_rss(opt={}, xslt=nil)
293
+ xslt ||= self.to_xslt(opt)
294
+ xml = Rexslt.new(xslt, self.to_xml).to_xml
295
+ "<rss version='2.0'>%s</rss>" % xml
289
296
  end
290
297
 
291
298
  def xpath(x)
@@ -304,6 +311,7 @@ EOF
304
311
  end
305
312
 
306
313
  def findx_by(field, value)
314
+ (load_records; rebuild_doc) if @dirty_flag == true
307
315
  r = @doc.root.element("records/*[#{field}='#{value}']")
308
316
  r ? recordx_to_record(r) : nil
309
317
  end
@@ -345,6 +353,7 @@ EOF
345
353
  end
346
354
 
347
355
  def display_xml(opt={})
356
+ load_records if @dirty_flag == true
348
357
  rebuild_doc()
349
358
  @doc.xml(opt) #jr230711 pretty: true
350
359
  end
@@ -369,7 +378,7 @@ EOF
369
378
  raw_summary = schema[/\[([^\]]+)/,1]
370
379
  raw_lines = buffer.gsub(/^\s*#[^\n]+/,'').gsub(/\n\n/,"\n")\
371
380
  .strip.split(/\r?\n|\r(?!\n)/)
372
-
381
+
373
382
  if raw_summary then
374
383
  a_summary = raw_summary.split(',').map(&:strip)
375
384
 
@@ -511,6 +520,7 @@ EOF
511
520
 
512
521
  #Returns a ready-only snapshot of records as a simple Hash.
513
522
  @flat_records = @records.values.map{|x| x[:body]}
523
+ @dirty_flag = false
514
524
  end
515
525
 
516
526
  def display()
@@ -550,4 +560,4 @@ EOF
550
560
  end
551
561
  end
552
562
 
553
- end
563
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.27
5
+ version: 1.1.28
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-05-19 00:00:00 Z
13
+ date: 2012-06-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rexle