dynarex 0.7.8 → 0.7.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dynarex.rb +7 -8
- metadata +2 -2
data/lib/dynarex.rb
CHANGED
@@ -123,9 +123,9 @@ EOF
|
|
123
123
|
# dynarex = Dynarex.new 'contacts/contact(name,age,dob)'
|
124
124
|
# dynarex.create name: Bob, age: 52
|
125
125
|
|
126
|
-
def create(arg)
|
126
|
+
def create(arg, id=nil)
|
127
127
|
methods = {Hash: :hash_create, String: :create_from_line}
|
128
|
-
send (methods[arg.class.to_s.to_sym]), arg
|
128
|
+
send (methods[arg.class.to_s.to_sym]), arg, id
|
129
129
|
|
130
130
|
load_records
|
131
131
|
self
|
@@ -137,7 +137,7 @@ EOF
|
|
137
137
|
# dynarex = Dynarex.new 'contacts/contact(name,age,dob)'
|
138
138
|
# dynarex.create_from_line 'Tracy 37 15-Jun-1972'
|
139
139
|
|
140
|
-
def create_from_line(line)
|
140
|
+
def create_from_line(line, id=nil)
|
141
141
|
t = @format_mask.to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
|
142
142
|
line.match(/#{t}/).captures
|
143
143
|
|
@@ -174,7 +174,7 @@ EOF
|
|
174
174
|
|
175
175
|
private
|
176
176
|
|
177
|
-
def hash_create(params={})
|
177
|
+
def hash_create(params={}, id=nil)
|
178
178
|
fields = capture_fields(params)
|
179
179
|
record = Element.new @record_name
|
180
180
|
fields.each do |k,v|
|
@@ -183,8 +183,8 @@ EOF
|
|
183
183
|
record.add element
|
184
184
|
end
|
185
185
|
|
186
|
-
ids = XPath.match(@doc.root,'records/*/attribute::id').map
|
187
|
-
id = ids.empty? ? 1 : ids.max.succ
|
186
|
+
ids = XPath.match(@doc.root,'records/*/attribute::id').map {|x| x.value.to_i}
|
187
|
+
id = ids.empty? ? (id || 1) : ids.max.succ
|
188
188
|
|
189
189
|
attributes = {id: id, created: Time.now.to_s, last_modified: nil}
|
190
190
|
attributes.each {|k,v| record.add_attribute(k.to_s, v)}
|
@@ -194,7 +194,6 @@ EOF
|
|
194
194
|
def capture_fields(params)
|
195
195
|
fields = Hash[@fields.map {|x| [x,nil]}]
|
196
196
|
fields.keys.each {|key| fields[key] = params[key] if params.has_key? key}
|
197
|
-
puts 'fields : ' + fields.inspect
|
198
197
|
fields
|
199
198
|
end
|
200
199
|
|
@@ -336,7 +335,7 @@ end))
|
|
336
335
|
r[node.name.to_s.to_sym] = node.text.to_s
|
337
336
|
r
|
338
337
|
end
|
339
|
-
|
338
|
+
|
340
339
|
[body[@default_key],{id: id, created: created, last_modified: \
|
341
340
|
last_modified, body: body}]
|
342
341
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynarex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.9
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-05-
|
12
|
+
date: 2010-05-18 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|