dynarex 0.7.7 → 0.7.8
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 +12 -11
- metadata +1 -1
data/lib/dynarex.rb
CHANGED
@@ -88,11 +88,11 @@ EOF
|
|
88
88
|
i = XPath.match(@doc.root, 'records/*/attribute::id').max_by(&:value).to_s.to_i
|
89
89
|
t = @format_mask.to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
|
90
90
|
lines = buffer.split(/\r?\n|\r(?!\n)/).map {|x|x.match(/#{t}/).captures}
|
91
|
-
|
91
|
+
|
92
92
|
a = lines.map do|x|
|
93
93
|
created = Time.now.to_s
|
94
94
|
|
95
|
-
h = Hash[fields.zip(x)]
|
95
|
+
h = Hash[@fields.zip(x)]
|
96
96
|
[h[@default_key.to_s], {id: '', created: created, last_modified: '', body: h}]
|
97
97
|
end
|
98
98
|
|
@@ -139,11 +139,10 @@ EOF
|
|
139
139
|
|
140
140
|
def create_from_line(line)
|
141
141
|
t = @format_mask.to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
|
142
|
-
fields = @format_mask.to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
|
143
142
|
line.match(/#{t}/).captures
|
144
143
|
|
145
144
|
a = line.match(/#{t}/).captures
|
146
|
-
h = Hash[fields.zip(a)]
|
145
|
+
h = Hash[@fields.zip(a)]
|
147
146
|
create h
|
148
147
|
self
|
149
148
|
end
|
@@ -193,8 +192,9 @@ EOF
|
|
193
192
|
end
|
194
193
|
|
195
194
|
def capture_fields(params)
|
196
|
-
fields = @fields.
|
195
|
+
fields = Hash[@fields.map {|x| [x,nil]}]
|
197
196
|
fields.keys.each {|key| fields[key] = params[key] if params.has_key? key}
|
197
|
+
puts 'fields : ' + fields.inspect
|
198
198
|
fields
|
199
199
|
end
|
200
200
|
|
@@ -251,10 +251,10 @@ EOF
|
|
251
251
|
end
|
252
252
|
|
253
253
|
def attach_record_methods()
|
254
|
-
@fields.
|
254
|
+
@fields.each do |field|
|
255
255
|
self.instance_eval(
|
256
256
|
%Q(def find_by_#{field}(s)
|
257
|
-
Hash[@fields.
|
257
|
+
Hash[@fields.zip(XPath.match(@doc.root, "records/*[#{field}='\#{s}']/*/text()").map &:to_s)]
|
258
258
|
end))
|
259
259
|
end
|
260
260
|
end
|
@@ -277,15 +277,15 @@ end))
|
|
277
277
|
@default_key = XPath.first(@doc.root, 'summary/default_key/text()')
|
278
278
|
@format_mask = XPath.first(@doc.root, 'summary/format_mask/text()')
|
279
279
|
|
280
|
-
|
280
|
+
@fields = @format_mask.to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym) if @format_mask
|
281
281
|
|
282
282
|
if @schema then
|
283
283
|
@record_name, raw_fields = @schema.match(/(\w+)\(([^\)]+)/).captures
|
284
|
-
@fields =
|
284
|
+
@fields = raw_fields.split(',').map{|x| x.strip.to_sym} unless @fields
|
285
285
|
end
|
286
286
|
|
287
287
|
if @fields then
|
288
|
-
@default_key = @fields
|
288
|
+
@default_key = @fields[0] unless @default_key
|
289
289
|
# load the record query handler methods
|
290
290
|
attach_record_methods
|
291
291
|
end
|
@@ -336,7 +336,8 @@ end))
|
|
336
336
|
r[node.name.to_s.to_sym] = node.text.to_s
|
337
337
|
r
|
338
338
|
end
|
339
|
-
|
339
|
+
puts 'default key : ' + @default_key
|
340
|
+
[body[@default_key],{id: id, created: created, last_modified: \
|
340
341
|
last_modified, body: body}]
|
341
342
|
end
|
342
343
|
Hash[*ah.flatten]
|