polyrex-createobject 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/polyrex-createobject.rb +12 -12
- metadata +2 -2
data/lib/polyrex-createobject.rb
CHANGED
@@ -3,12 +3,11 @@
|
|
3
3
|
# file: polyrex-createobject.rb
|
4
4
|
|
5
5
|
require 'polyrex-schema'
|
6
|
-
require '
|
6
|
+
require 'rexle'
|
7
7
|
|
8
8
|
class PolyrexCreateObject
|
9
|
-
include REXML
|
10
9
|
|
11
|
-
attr_accessor :id
|
10
|
+
attr_accessor :id, :parent_node
|
12
11
|
|
13
12
|
def initialize(schema, id='1')
|
14
13
|
@id = id
|
@@ -29,10 +28,11 @@ class PolyrexCreateObject
|
|
29
28
|
|
30
29
|
def attach_create_handlers(names)
|
31
30
|
methodx = names[0..-2].map do |name, xpath|
|
31
|
+
|
32
32
|
%Q(
|
33
33
|
def #{name}(params={}, id=nil,&blk)
|
34
|
-
|
35
|
-
create_node(
|
34
|
+
self.record = @parent_node.element('records')
|
35
|
+
self.record = create_node(@parent_node, @rpaths['#{xpath}'], params, id)
|
36
36
|
blk.call(self) if blk
|
37
37
|
self
|
38
38
|
end
|
@@ -42,8 +42,8 @@ class PolyrexCreateObject
|
|
42
42
|
name, xpath = names[-1]
|
43
43
|
|
44
44
|
methodx << %Q(
|
45
|
-
def #{name}(params={}, id=nil,&blk)
|
46
|
-
self.record =
|
45
|
+
def #{name}(params={}, id=nil,&blk)
|
46
|
+
self.record = @parent_node.element('records')
|
47
47
|
self.record = create_node(@parent_node, @rpaths['#{xpath}'], params, id)
|
48
48
|
blk.call(self) if blk
|
49
49
|
self
|
@@ -56,19 +56,19 @@ end
|
|
56
56
|
|
57
57
|
def create_node(parent_node, child_schema, params={}, id=nil)
|
58
58
|
|
59
|
-
record =
|
59
|
+
record = Rexle.new PolyrexSchema.new(child_schema).to_s
|
60
60
|
@id = id if id
|
61
61
|
|
62
|
-
record.root.add_attribute('id'
|
62
|
+
record.root.add_attribute({'id' => @id.to_s.clone})
|
63
63
|
if @id.to_s[/[0-9]/] then
|
64
64
|
@id.succ!
|
65
65
|
else
|
66
|
-
@id =
|
66
|
+
@id = @parent_node.element('count(//@id)').to_i + 2
|
67
67
|
end
|
68
68
|
|
69
69
|
a = child_schema[/[^\[]+(?=\])/].split(',')
|
70
70
|
a.each do |field_name|
|
71
|
-
field =
|
71
|
+
field = record.element('summary/' + field_name)
|
72
72
|
field.text = params[field_name.to_sym]
|
73
73
|
end
|
74
74
|
|
@@ -81,4 +81,4 @@ end
|
|
81
81
|
xpath.split('/').each_slice(2).map(&:last).join('/').gsub(/\[[^\]]+\]/,'')
|
82
82
|
end
|
83
83
|
|
84
|
-
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-createobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
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-
|
12
|
+
date: 2010-12-01 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|