polyrex-createobject 0.4.15 → 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/polyrex-createobject.rb +132 -47
- metadata +29 -21
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d06a5b8d9fa6ddadaf9f2293ce65ed07c22e0d2d
|
4
|
+
data.tar.gz: c8a635cf6570fc68b1a15e54a7765279a3247dbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7def32cabec4f6634064638be39a5eb872e56a23d8d95ebab0904daa8c3ca5350b7915cdb04b1685fce334d0244fa72a92ad07716800d9758613884a97217dfa
|
7
|
+
data.tar.gz: d16b6325fe8b98fafa1e61aae27c168dadb3afab527dd552f7b0385565beb57d8bb8873f5930cd6d19b1a5f4ebf7fd3e98f3d2b92e52ab667136efc8eaff166e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/polyrex-createobject.rb
CHANGED
@@ -2,35 +2,50 @@
|
|
2
2
|
|
3
3
|
# file: polyrex-createobject.rb
|
4
4
|
|
5
|
-
|
5
|
+
|
6
6
|
require 'rexle'
|
7
|
+
require 'polyrex-schema'
|
7
8
|
|
8
9
|
|
9
10
|
class PolyrexCreateObject
|
10
11
|
|
11
12
|
attr_accessor :parent_node
|
12
|
-
|
13
|
+
attr_reader :obj
|
14
|
+
|
15
|
+
|
13
16
|
def initialize(schema, id='1')
|
17
|
+
|
14
18
|
@@id = id
|
15
19
|
|
16
|
-
|
20
|
+
raise "missing schema" unless schema
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
@schema = schema[/\/.*$/][1..-1]
|
23
|
+
a = PolyrexSchema.new(schema).to_a
|
24
|
+
@obj = attach_create_handlers(a)
|
25
|
+
|
26
|
+
@obj.class_eval do
|
27
|
+
def record=(node)
|
28
|
+
@parent_node = node
|
22
29
|
end
|
30
|
+
end
|
23
31
|
|
24
|
-
|
32
|
+
self.instance_eval " def #{@obj.name.downcase}(h, id=@@id, &blk)
|
25
33
|
|
26
|
-
@
|
27
|
-
@rpaths[key] = values[i..-1].join('/')
|
28
|
-
end
|
34
|
+
new_parent = create_node(@parent_node, @schema, h, id).element('records')
|
29
35
|
|
30
|
-
|
36
|
+
obj = @obj.new
|
37
|
+
obj.record = new_parent
|
38
|
+
obj.instance_variable_set(:@schema, @schema[/\\/(.*$)/,1])
|
31
39
|
|
32
|
-
|
40
|
+
|
41
|
+
if block_given? then
|
42
|
+
blk.call obj
|
43
|
+
else
|
44
|
+
obj
|
45
|
+
end
|
33
46
|
end
|
47
|
+
"
|
48
|
+
|
34
49
|
end
|
35
50
|
|
36
51
|
def id=(s) @@id = s; self end
|
@@ -40,51 +55,60 @@ class PolyrexCreateObject
|
|
40
55
|
@parent_node = node
|
41
56
|
end
|
42
57
|
|
43
|
-
|
44
|
-
methodx = names[0..-2].map do |name, xpath|
|
58
|
+
private
|
45
59
|
|
46
|
-
|
47
|
-
%Q(
|
48
|
-
def #{name}(params={}, id=nil,&blk)
|
60
|
+
def attach_create_handlers(a)
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
62
|
+
class_name = "root".capitalize
|
63
|
+
parent_klass = Object.const_set(class_name,Class.new)
|
64
|
+
result = scan parent_klass, a
|
65
|
+
end
|
53
66
|
|
54
|
-
|
55
|
-
self.record = new_parent
|
56
|
-
blk.call(self)
|
57
|
-
end
|
67
|
+
def create_node(parent_node, child_schema, params={}, id=nil)
|
58
68
|
|
59
|
-
|
69
|
+
buffer = PolyrexSchema.new(child_schema[/^[^\/]+/]).to_s
|
70
|
+
record = Rexle.new buffer
|
60
71
|
|
61
|
-
|
62
|
-
|
63
|
-
|
72
|
+
if id then
|
73
|
+
@@id.succ!
|
74
|
+
else
|
75
|
+
if @@id.to_i.to_s == @@id.to_s then
|
76
|
+
@@id.succ!
|
77
|
+
else
|
78
|
+
@@id = @parent_node.element('count(//@id)').to_i + 2
|
79
|
+
end
|
64
80
|
end
|
65
81
|
|
66
|
-
|
82
|
+
record.root.add_attribute({'id' => @@id.to_s.clone})
|
83
|
+
|
84
|
+
a = child_schema[/[^\[]+(?=\])/].split(',')
|
67
85
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
self.record = @parent_node.element('records') unless @parent_node.name == 'records'
|
74
|
-
self.record = create_node(@parent_node, @rpaths['#{xpath}'], params, id).element('records')
|
75
|
-
blk.call(self) if block_given?
|
76
|
-
self.record = orig_parent
|
86
|
+
summary = record.root.element('summary')
|
87
|
+
a.each do |field_name|
|
88
|
+
field = summary.element(field_name.strip)
|
89
|
+
field.text = params[field_name.strip.to_sym]
|
90
|
+
end
|
77
91
|
|
78
|
-
|
79
|
-
end
|
80
|
-
)
|
92
|
+
parent_node.add record.root
|
81
93
|
|
82
|
-
self.instance_eval(methodx.join("\n"))
|
83
|
-
|
84
94
|
end
|
85
95
|
|
86
|
-
def
|
96
|
+
def scan(parent, list)
|
97
|
+
|
98
|
+
record = list.shift
|
99
|
+
args = list
|
100
|
+
|
101
|
+
r = []
|
102
|
+
|
103
|
+
fields = []
|
104
|
+
fields << args.shift while args.first.is_a? Symbol
|
105
|
+
|
106
|
+
class_name = record.capitalize
|
107
|
+
klass = Object.const_set(class_name,Class.new)
|
87
108
|
|
109
|
+
parent.class_eval do
|
110
|
+
|
111
|
+
define_method :create_node do |parent_node, child_schema, params={}, id=nil|
|
88
112
|
|
89
113
|
buffer = PolyrexSchema.new(child_schema[/^[^\/]+/]).to_s
|
90
114
|
record = Rexle.new buffer
|
@@ -114,8 +138,69 @@ end
|
|
114
138
|
end
|
115
139
|
|
116
140
|
|
117
|
-
|
118
|
-
|
141
|
+
define_method record do |h, id=nil, &blk|
|
142
|
+
|
143
|
+
id ||= @@id
|
144
|
+
local_schema = "%s[%s]" % [record, fields.join(',')]
|
145
|
+
new_parent = create_node(@parent_node, local_schema, h, id).element('records')
|
146
|
+
|
147
|
+
obj = klass.new
|
148
|
+
|
149
|
+
def obj.record=(node)
|
150
|
+
@parent_node = node
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
obj.record = new_parent
|
155
|
+
#if block_given? then
|
156
|
+
if blk then
|
157
|
+
blk.call obj
|
158
|
+
else
|
159
|
+
obj
|
160
|
+
end
|
161
|
+
self
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
return klass unless args.any?
|
166
|
+
|
167
|
+
next_rec = args.shift
|
168
|
+
|
169
|
+
if next_rec.first.is_a? Array then
|
170
|
+
remaining = scan(parent, *args) unless args.length < 1
|
171
|
+
|
172
|
+
next_rec.each do |x|
|
173
|
+
|
174
|
+
child_klass = scan(klass,x)
|
175
|
+
|
176
|
+
if remaining then
|
177
|
+
|
178
|
+
child_klass.class_eval do
|
179
|
+
|
180
|
+
define_method remaining.name.downcase.to_sym do |h, id=nil, &blk|
|
181
|
+
|
182
|
+
id ||= @@id
|
183
|
+
local_schema = "%s[%s]" % [record, fields.join(',')]
|
184
|
+
|
185
|
+
new_parent = create_node(@parent_node, local_schema, params, id).element('records')
|
186
|
+
|
187
|
+
obj = remaining.new
|
188
|
+
obj.record = new_parent
|
189
|
+
yield obj
|
190
|
+
|
191
|
+
self
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
else
|
198
|
+
remaining = scan(klass, *list) unless args.length < 1
|
199
|
+
scan(klass, next_rec)
|
200
|
+
scan(r, remaining) if remaining
|
201
|
+
end
|
202
|
+
|
203
|
+
return klass
|
119
204
|
end
|
120
205
|
|
121
206
|
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.4.
|
4
|
+
version: 0.4.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,41 +10,49 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
14
|
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
-
|
15
|
+
8ixkARkWAmV1MB4XDTE0MDYxMDE4NTQyNFoXDTE1MDYxMDE4NTQyNFowSDESMBAG
|
16
16
|
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
17
|
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
ggEBANl/vg+k69QF/+07LT7xiONXbg1eQuOIsF8pkF++AC6b3qYjrqw8QyUWIBEj
|
19
|
+
4QDhbbODoUkQZ+RSncX0zyf7ss2fQ2xfqWbWwK5QAucpjMGEX7NIIOqM78tnqQm/
|
20
|
+
LaCUpFGYBIj5K3GmqQEk2yrZDBoqvaCCuP7BT5NKeK3wQQbTiqREf+6oyMggUAPE
|
21
|
+
d5XAWThFlzja93uiL5/B5vhu4xODqHXOkHqno/oPQ+Dcyn1qP7U61NLKcm1ors2Y
|
22
|
+
cbQglfBy1xroiGBgIdwW61q68NILVpHQsJ1AjeZw4WeqmIHZS7nOI2K2WYG0adr8
|
23
|
+
7Xfy3vLCwMhRjSTXj+yo2kWUSn0CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUtGGpyfWCH4LJIx9manZK+J2zqk8wJgYDVR0RBB8w
|
25
|
+
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAHZjkoDAi
|
27
|
+
3UAg3FY+RMafVDw/0nkwYLgXtmEVk2YHuOKZKY9g+7xCG6/v+jspzgyndPl0oIeG
|
28
|
+
ED4p8UbmQt5wPQwhWU/6hZaVRe6n/PBtgbktCaU4bVjlE+84s11J7rHMWIUbykKs
|
29
|
+
8FO2zKoVjq6hCMxrYgs2u0++Ju5E1rvppHqMyrzeJzwmkW3XXsCvdR1Wqvg3cath
|
30
|
+
Ro9OPaTvLpSW/gRNa3cYnUAT2nbiPO2hzjzMcHkMviDtllJpwZgCLGPe8sHBzb95
|
31
|
+
f3O5lCaUfMDZbRHRyvXjy/4PFRQKLr6ZLbpQN+dWceS6/82/5xWEL/7Bo/86R5xN
|
32
|
+
JL6pGH//inbMWQ==
|
31
33
|
-----END CERTIFICATE-----
|
32
|
-
date: 2014-
|
34
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
33
35
|
dependencies:
|
34
36
|
- !ruby/object:Gem::Dependency
|
35
37
|
name: polyrex-schema
|
36
38
|
requirement: !ruby/object:Gem::Requirement
|
37
39
|
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.1'
|
38
43
|
- - ">="
|
39
44
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
45
|
+
version: 0.1.16
|
41
46
|
type: :runtime
|
42
47
|
prerelease: false
|
43
48
|
version_requirements: !ruby/object:Gem::Requirement
|
44
49
|
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.1'
|
45
53
|
- - ">="
|
46
54
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
55
|
+
version: 0.1.16
|
48
56
|
description:
|
49
57
|
email: james@r0bertson.co.uk
|
50
58
|
executables: []
|
@@ -64,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
72
|
requirements:
|
65
73
|
- - ">="
|
66
74
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
75
|
+
version: 2.1.2
|
68
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
77
|
requirements:
|
70
78
|
- - ">="
|
@@ -72,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
80
|
version: '0'
|
73
81
|
requirements: []
|
74
82
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.2.2
|
76
84
|
signing_key:
|
77
85
|
specification_version: 4
|
78
86
|
summary: polyrex-createobject
|
metadata.gz.sig
CHANGED
Binary file
|