polyrex-createobject 0.1.3 → 0.1.4
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/polyrex-createobject.rb +10 -9
- metadata +1 -1
data/lib/polyrex-createobject.rb
CHANGED
@@ -30,9 +30,9 @@ class PolyrexCreateObject
|
|
30
30
|
def attach_create_handlers(names)
|
31
31
|
methodx = names[0..-2].map do |name, xpath|
|
32
32
|
%Q(
|
33
|
-
def #{name}(params)
|
33
|
+
def #{name}(params={}, id=nil)
|
34
34
|
records = XPath.first(@parent_node,'records')
|
35
|
-
create_node(records, @rpaths['#{xpath}'], params)
|
35
|
+
create_node(records, @rpaths['#{xpath}'], params, id)
|
36
36
|
self
|
37
37
|
end
|
38
38
|
)
|
@@ -41,9 +41,9 @@ class PolyrexCreateObject
|
|
41
41
|
name, xpath = names[-1]
|
42
42
|
|
43
43
|
methodx << %Q(
|
44
|
-
def #{name}(params)
|
44
|
+
def #{name}(params={}, id=nil)
|
45
45
|
@parent_node = XPath.first(@parent_node.root,'records')
|
46
|
-
record = create_node(@parent_node, @rpaths['#{xpath}'], params)
|
46
|
+
record = create_node(@parent_node, @rpaths['#{xpath}'], params, id)
|
47
47
|
self
|
48
48
|
end
|
49
49
|
)
|
@@ -52,16 +52,17 @@ end
|
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
-
def create_node(parent_node, child_schema, params)
|
55
|
+
def create_node(parent_node, child_schema, params={}, id=nil)
|
56
56
|
raise "create_node error: can't create record" unless valid_creation?
|
57
57
|
record = Document.new PolyrexSchema.new(child_schema).to_s
|
58
|
+
@id = id if id
|
58
59
|
|
59
|
-
|
60
|
-
record.root.add_attribute('id', @id)
|
61
|
-
if @id[/[0-9]/] then
|
60
|
+
puts 'id : ' + @id.to_s
|
61
|
+
record.root.add_attribute('id', @id.to_s)
|
62
|
+
if @id.to_s[/[0-9]/] then
|
62
63
|
@id = (@id.to_i + 1).to_s
|
63
64
|
else
|
64
|
-
@id = XPath.first(@parent_node
|
65
|
+
@id = XPath.first(@parent_node.root, 'count(//@id)').to_i + 1
|
65
66
|
end
|
66
67
|
|
67
68
|
a = child_schema[/[^\[]+(?=\])/].split(',')
|