polyrex-objects 0.9.8 → 1.0.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -3
- data.tar.gz.sig +0 -0
- data/lib/polyrex-objects.rb +86 -184
- metadata +27 -28
- metadata.gz.sig +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1acdaea24860535ed620cd454e7487e9ab4c2cc9
|
4
|
+
data.tar.gz: 1c66171b97eff79522e3b3a31aaba93d72ac905d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e82afb248958a8e9f64afd3e16a80f81a28152f7c3926cee8f79a18a2c4496bc1eff5f7d17127f44a3a8cb47919ab6a2051cb6a9dda03d36db48157236b3e63
|
7
|
+
data.tar.gz: c5b5202f30fade92f4583848ebe7b34f06e2cce2b5baa6cbfc8e26623c99ff747fcf227fd7a95b13f7ba7c2e747ecb7147d9bfe32eaf11f009ca1b4ae4b13c64
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
�SY)����SBݐ�rZUʪ��4�Sa���, �Q��`��LU��V���$���\�N�&$)�X|�p����j���0�2�h��w������"gf�^�+�Wh���uj?�˸��`/1���Žp7L:�"%����Z�W�����ËOg�5IE���$�����͛O�I-o��ti�xm
|
1
|
+
R����;X��]�FG[�:������w^�T�1�7��z!Z�g�����
|
2
|
+
��z@X܂
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/polyrex-objects.rb
CHANGED
@@ -9,20 +9,28 @@ require 'rexle'
|
|
9
9
|
|
10
10
|
class PolyrexObjects
|
11
11
|
|
12
|
-
|
13
12
|
class PolyrexObject
|
14
13
|
|
15
|
-
|
14
|
+
def initialize(node, id: '0', debug: true)
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
@@id = id
|
20
|
-
@node = node
|
16
|
+
@id = id
|
21
17
|
@fields =[]
|
22
|
-
@
|
18
|
+
@node, @debug = node, debug
|
19
|
+
|
20
|
+
e = node.element('summary')
|
21
|
+
@schema = e.text('schema')
|
22
|
+
@child_schema = @schema =~ /\// ? @schema[/(?<=\/).*/] : @schema
|
23
|
+
puts '@child_schema:' + @child_schema.inspect if @debug
|
24
|
+
@record = @schema[/^[^\[]+/]
|
25
|
+
@fields = @schema[/(?<=\[)[^\]]+/].split(/ *, */)
|
23
26
|
|
27
|
+
attr = @fields.map {|x| [x, e.text(x)] }
|
28
|
+
build_attributes attr
|
29
|
+
|
30
|
+
define_singleton_method(@record.to_sym) { self.records}
|
31
|
+
|
24
32
|
end
|
25
|
-
|
33
|
+
|
26
34
|
def add(pxobj)
|
27
35
|
@node.element('records').add pxobj.node
|
28
36
|
end
|
@@ -40,14 +48,9 @@ class PolyrexObjects
|
|
40
48
|
self.records.length
|
41
49
|
end
|
42
50
|
|
43
|
-
def create(id:
|
44
|
-
id ||=@@id
|
45
|
-
|
46
|
-
id.succ!
|
47
|
-
@create.id = id
|
51
|
+
def create(id: @id)
|
48
52
|
|
49
|
-
|
50
|
-
@create
|
53
|
+
PolyrexCreateObject.new(id: id, record: @node)
|
51
54
|
end
|
52
55
|
|
53
56
|
def css(s)
|
@@ -83,7 +86,7 @@ class PolyrexObjects
|
|
83
86
|
end
|
84
87
|
|
85
88
|
def inspect()
|
86
|
-
"
|
89
|
+
"#<%s:%s" % [self.class.name, __id__]
|
87
90
|
end
|
88
91
|
|
89
92
|
def [](n)
|
@@ -93,8 +96,9 @@ class PolyrexObjects
|
|
93
96
|
def parent()
|
94
97
|
|
95
98
|
parent_node = self.node.parent.parent
|
96
|
-
|
97
|
-
|
99
|
+
|
100
|
+
Kernel.const_get(parent_node.name.capitalize)\
|
101
|
+
.new(parent_node, id: parent_node.attributes[:id])
|
98
102
|
|
99
103
|
end
|
100
104
|
|
@@ -105,7 +109,15 @@ class PolyrexObjects
|
|
105
109
|
|
106
110
|
node.parent.parent.parent.parent ? true : false
|
107
111
|
end
|
108
|
-
|
112
|
+
|
113
|
+
def records()
|
114
|
+
|
115
|
+
@node.xpath('records/*').map do |node|
|
116
|
+
Kernel.const_get(node.name.capitalize).new node
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
109
121
|
def to_doc()
|
110
122
|
Rexle.new @node.to_a
|
111
123
|
end
|
@@ -129,25 +141,25 @@ class PolyrexObjects
|
|
129
141
|
xsl_buffer =<<EOF
|
130
142
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
131
143
|
<xsl:output encoding="UTF-8"
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
indent="yes"
|
145
|
+
omit-xml-declaration="yes"/>
|
146
|
+
|
147
|
+
<xsl:template match="*">
|
148
|
+
<xsl:element name="{name()}">
|
149
|
+
<xsl:element name="summary">
|
150
|
+
<xsl:for-each select="summary/*">
|
151
|
+
<xsl:copy-of select="."/>
|
152
|
+
</xsl:for-each>
|
153
|
+
</xsl:element>
|
154
|
+
<xsl:element name="records">
|
155
|
+
<xsl:for-each select="records/*">
|
156
|
+
<xsl:element name="{name()}">
|
157
|
+
<xsl:copy-of select="summary/*"/>
|
158
|
+
</xsl:element>
|
159
|
+
</xsl:for-each>
|
160
|
+
</xsl:element>
|
161
|
+
</xsl:element>
|
162
|
+
</xsl:template>
|
151
163
|
</xsl:stylesheet>
|
152
164
|
EOF
|
153
165
|
|
@@ -165,13 +177,12 @@ EOF
|
|
165
177
|
|
166
178
|
end
|
167
179
|
|
168
|
-
|
169
180
|
def to_h()
|
170
181
|
@fields.inject({}) do |r, field|
|
171
182
|
r.merge(field=> self.method(field).call)
|
172
183
|
end
|
173
184
|
end
|
174
|
-
|
185
|
+
|
175
186
|
def to_s()
|
176
187
|
|
177
188
|
if self.respond_to? :records then
|
@@ -199,9 +210,28 @@ EOF
|
|
199
210
|
def xpath(s)
|
200
211
|
@node.xpath(s)
|
201
212
|
end
|
202
|
-
|
213
|
+
|
203
214
|
private
|
204
|
-
|
215
|
+
|
216
|
+
def build_attributes(attr=[])
|
217
|
+
|
218
|
+
attr.each do |name, value|
|
219
|
+
|
220
|
+
var = name.to_s
|
221
|
+
get, set = var.to_sym, (var + '=').to_sym
|
222
|
+
|
223
|
+
define_singleton_method(get) do
|
224
|
+
@node.element("summary/#{__callee__}/text()").to_s
|
225
|
+
end
|
226
|
+
|
227
|
+
define_singleton_method(set) do |v|
|
228
|
+
@node.element("summary/#{(__callee__).to_s.chop}").text = v.to_s
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
205
235
|
def build(records, indent=0)
|
206
236
|
|
207
237
|
records.map do |item|
|
@@ -217,157 +247,29 @@ EOF
|
|
217
247
|
end
|
218
248
|
(' ' * indent) + line
|
219
249
|
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def initialize(schema, node=nil, id: '0')
|
224
|
-
|
225
|
-
@node = node
|
226
|
-
@@id = id
|
250
|
+
end
|
227
251
|
|
228
|
-
|
252
|
+
end
|
229
253
|
|
230
|
-
|
231
|
-
|
232
|
-
@class_names = []
|
254
|
+
def initialize(schema, debug: false)
|
233
255
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
a.each do |x|
|
238
|
-
make_class(x[:name], x[:fields], x[:schema])
|
239
|
-
scan.call(x[:children]) if x[:children]
|
240
|
-
end
|
241
|
-
end
|
256
|
+
@debug = debug
|
257
|
+
record_names = schema.scan(/(?<=\/)\w+/)
|
258
|
+
puts 'record_names: ' + record_names.inspect if @debug
|
242
259
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
else
|
248
|
-
# implement the child_object within each class object
|
249
|
-
@class_names[0..-2].reverse.each_with_index do |class_name, k|
|
250
|
-
|
251
|
-
i = @class_names.length - (k + 1)
|
252
|
-
make_def_records(class_name,i)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
@class_names[1..-1].each_with_index do |class_name, k|
|
256
|
-
eval "#{class_name}.class_eval {
|
257
|
-
def parent()
|
258
|
-
#{@class_names[k]}.new(@node.parent.parent, id: @@id)
|
259
|
-
end
|
260
|
-
}"
|
261
|
-
end
|
262
|
-
|
263
|
-
methodx = @class_names.map do |name|
|
264
|
-
%Q(def #{name.downcase}(); #{name}.new(@node, id: @@id); end)
|
265
|
-
end
|
266
|
-
|
267
|
-
self.instance_eval(methodx.join("\n"))
|
260
|
+
@classes = record_names.inject({}) do |r, name|
|
261
|
+
puts 'name: ' + name.inspect if @debug
|
262
|
+
r.merge!({name.to_sym => \
|
263
|
+
(Object.const_set name.capitalize, Class.new(PolyrexObject))})
|
268
264
|
end
|
269
|
-
end
|
270
265
|
|
271
|
-
def to_a
|
272
|
-
@class_names.map {|x| eval(x.to_s)}
|
273
266
|
end
|
274
|
-
|
275
|
-
def to_h
|
276
|
-
Hash[self.to_a.map {|x| [x.name[/\w+$/], x]}]
|
277
|
-
end
|
278
|
-
|
279
|
-
private
|
280
|
-
|
281
|
-
def make_class(name, fields, schema=@schema)
|
282
|
-
|
283
|
-
if fields then
|
284
|
-
|
285
|
-
@class_names << name.capitalize
|
286
|
-
|
287
|
-
classx = []
|
288
|
-
classx << "class #{name.capitalize} < PolyrexObject"
|
289
|
-
classx << "def initialize(node=nil, id: '0', objects: nil)"
|
290
|
-
classx << " @id = id"
|
291
|
-
classx << " node ||= Rexle.new('<#{name}><summary/><records/></#{name}>').root"
|
292
|
-
classx << " super(node, id: id, objects: objects)"
|
293
|
-
|
294
|
-
classx << " a = node.xpath('summary/*',&:name)"
|
295
|
-
classx << " yaml_fields = a - (#{fields} + %w(format_mask))"
|
296
|
-
classx << "yaml_fields.each do |field|"
|
297
|
-
classx << %q( "def self.#{field})
|
298
|
-
classx << %q( s = @node.element('summary/#{field}/text()'))
|
299
|
-
classx << %q( s[/^---/] ? YAML.load(s) : s)
|
300
|
-
classx << %q( end")
|
301
|
-
classx << "end"
|
302
|
-
|
303
|
-
classx << "@fields = %i(#{fields.join(' ')})"
|
304
|
-
classx << "@create = PolyrexCreateObject.new('#{@schema[/\/(.*)/,1]}', id: '#{@id}')"
|
305
|
-
classx << "end"
|
306
|
-
|
307
|
-
fields.each do |field|
|
308
|
-
classx << "def #{field}"
|
309
|
-
classx << " if @node.element('summary/#{field}').nil? then"
|
310
|
-
classx << " @node.element('summary').add Rexle::Element.new('#{field}')"
|
311
|
-
classx << " end"
|
312
|
-
classx << " node = @node.element('summary/#{field}/text()')"
|
313
|
-
classx << " node ? node.clone : ''"
|
314
|
-
classx << "end"
|
315
|
-
classx << "def #{field}=(text)"
|
316
|
-
classx << " if @node.element('summary/#{field}').nil? then"
|
317
|
-
classx << " @node.element('summary').add Rexle::Element.new('#{field}', value: text)"
|
318
|
-
classx << " else"
|
319
|
-
classx << " @node.element('summary/#{field}').text = text"
|
320
|
-
classx << " end"
|
321
|
-
classx << "end"
|
322
|
-
end
|
323
267
|
|
324
|
-
|
325
|
-
|
326
|
-
eval classx.join("\n")
|
327
|
-
end
|
268
|
+
def to_h
|
269
|
+
@classes
|
328
270
|
end
|
329
271
|
|
330
|
-
def
|
331
|
-
|
332
|
-
eval "#{class_name}.class_eval {
|
333
|
-
def records()
|
334
|
-
|
335
|
-
classes = {#{@class_names.map{|x| %Q(%s: %s) % [x[/[^:]+$/].downcase,x]}.join(',')} }
|
336
|
-
|
337
|
-
objects = @node.xpath('records/*').map do |record|
|
338
|
-
classes[record.name.to_sym].new(record, id: '#{@@id}')
|
339
|
-
end
|
340
|
-
|
341
|
-
def objects.records=(node); @node = node; end
|
342
|
-
def objects.records(); @node; end
|
343
|
-
|
344
|
-
def objects.sort_by!(&element_blk)
|
345
|
-
a = @node.xpath('records/*').sort_by &element_blk
|
346
|
-
records = @node.xpath('records')
|
347
|
-
records.delete
|
348
|
-
records = Rexle::Element.new 'records'
|
349
|
-
a.each {|record| records.add record}
|
350
|
-
@node.add records
|
351
|
-
@node.xpath('records/*').map {|record| #{@class_names[i]}.new(record)}
|
352
|
-
end
|
353
|
-
|
354
|
-
objects.records = @node
|
355
|
-
|
356
|
-
def objects.remove_all()
|
357
|
-
e = @node.element('records')
|
358
|
-
e.insert_before Rexle::Element.new('records')
|
359
|
-
e.delete
|
360
|
-
end
|
361
|
-
|
362
|
-
objects
|
363
|
-
end
|
364
|
-
|
365
|
-
alias #{@class_names[i].downcase} records
|
366
|
-
|
367
|
-
}"
|
368
|
-
|
272
|
+
def to_a
|
273
|
+
@classes.to_a
|
369
274
|
end
|
370
|
-
|
371
|
-
|
372
|
-
|
373
275
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,27 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
s9lI00OyqNZ3ww==
|
13
|
+
MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM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qE/kxM
|
29
|
+
Ub/kjgBxH7GEfO1fPRZxK1+xOKc7oVr7y4Hpxm1+AVC6OpMCbn+5QTG1VrzSgPxb
|
30
|
+
ACBQhlVD3BfBw9Dgn9grd+SUOEmogOVDxNTXoL3fdgzYlSbv9YnK3csMPjzbMR6y
|
31
|
+
3O0=
|
33
32
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
33
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
35
34
|
dependencies:
|
36
35
|
- !ruby/object:Gem::Dependency
|
37
36
|
name: polyrex-createobject
|
@@ -39,22 +38,22 @@ dependencies:
|
|
39
38
|
requirements:
|
40
39
|
- - "~>"
|
41
40
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
41
|
+
version: '0.7'
|
43
42
|
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
44
|
+
version: 0.7.0
|
46
45
|
type: :runtime
|
47
46
|
prerelease: false
|
48
47
|
version_requirements: !ruby/object:Gem::Requirement
|
49
48
|
requirements:
|
50
49
|
- - "~>"
|
51
50
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0.
|
51
|
+
version: '0.7'
|
53
52
|
- - ">="
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
54
|
+
version: 0.7.0
|
56
55
|
description:
|
57
|
-
email: james@
|
56
|
+
email: james@jamesrobertson.eu
|
58
57
|
executables: []
|
59
58
|
extensions: []
|
60
59
|
extra_rdoc_files: []
|
@@ -80,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
79
|
version: '0'
|
81
80
|
requirements: []
|
82
81
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.6.13
|
84
83
|
signing_key:
|
85
84
|
specification_version: 4
|
86
85
|
summary: Polyrex-objects automically builds objects from a Polyrex schema
|
metadata.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
��
|
1
|
+
P7�M[�1�F����O�vp5�5&���J�|�/��r��|�@n7ٞ�w�W΅ߜy��+��3X�qˮKPZmwY 5����Iq)�]�fiU� �"�B곿�Z�\X��qdW��+�k �d��=Μ)����גy�����'>���HT�F5RE<�����z��4oVĵ��pߪ���!�&9�f�Xo��<7g϶�SN��})����㪁&��ۑsڊU�W+o��ʌJ�;�y
|