polyrex-objects 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/polyrex-objects.rb +11 -11
- metadata +11 -9
data/lib/polyrex-objects.rb
CHANGED
@@ -10,7 +10,7 @@ class PolyrexObjects
|
|
10
10
|
def initialize(schema, node=nil, id=nil)
|
11
11
|
|
12
12
|
@node = node
|
13
|
-
|
13
|
+
@@id = id
|
14
14
|
|
15
15
|
a = schema.split('/')
|
16
16
|
a.shift
|
@@ -25,12 +25,12 @@ class PolyrexObjects
|
|
25
25
|
classx = []
|
26
26
|
classx << "class #{name.capitalize}"
|
27
27
|
classx << "def initialize(node, id=nil)"
|
28
|
-
classx << "
|
28
|
+
classx << "@@id=id; @node = node;"
|
29
29
|
classx << "@create = PolyrexCreateObject.new('#{schema}')"
|
30
30
|
classx << "end"
|
31
31
|
fields.each do |field|
|
32
|
-
|
33
|
-
|
32
|
+
classx << "def #{field}; @node.element('summary/#{field}/text()'); end"
|
33
|
+
classx << "def #{field}=(text); @node.element('summary/#{field}').text = text; end"
|
34
34
|
end
|
35
35
|
classx << "def to_xml(options={}); @node.xml(options); end"
|
36
36
|
classx << "def with(); yield(self); end"
|
@@ -45,14 +45,14 @@ class PolyrexObjects
|
|
45
45
|
i = @class_names.length - (k + 1)
|
46
46
|
eval "#{class_name}.class_eval {
|
47
47
|
def records()
|
48
|
-
|
48
|
+
objects = @node.xpath('records/*').map {|record| #{@class_names[i]}.new(record)}
|
49
49
|
|
50
50
|
def objects.records=(node); @node = node; end
|
51
51
|
def objects.records(); @node; end
|
52
52
|
|
53
53
|
def objects.sort_by!(&element_blk)
|
54
|
-
|
55
|
-
|
54
|
+
a = @node.xpath('records/*').sort_by &element_blk
|
55
|
+
records = @node.xpath('records')
|
56
56
|
records.delete
|
57
57
|
records = Rexle::Element.new 'records'
|
58
58
|
a.each {|record| records.add record}
|
@@ -65,9 +65,9 @@ class PolyrexObjects
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def create(id=nil)
|
68
|
-
@create.id = id ||
|
69
|
-
|
70
|
-
@create.record = @node
|
68
|
+
@create.id = id || @@id
|
69
|
+
@@id.succ!
|
70
|
+
@create.record = @node.element('records')
|
71
71
|
@create
|
72
72
|
end
|
73
73
|
|
@@ -85,7 +85,7 @@ class PolyrexObjects
|
|
85
85
|
end
|
86
86
|
|
87
87
|
methodx = @class_names.map do |name|
|
88
|
-
%Q(def #{name.downcase}(); #{name}.new(@node,
|
88
|
+
%Q(def #{name.downcase}(); #{name}.new(@node, @@id); end)
|
89
89
|
end
|
90
90
|
|
91
91
|
self.instance_eval(methodx.join("\n"))
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.6.5
|
5
6
|
platform: ruby
|
6
7
|
authors: []
|
7
8
|
|
@@ -9,19 +10,20 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2011-
|
13
|
+
date: 2011-03-15 00:00:00 +00:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: polyrex-createobject
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
20
21
|
requirements:
|
21
22
|
- - ">="
|
22
23
|
- !ruby/object:Gem::Version
|
23
24
|
version: "0"
|
24
|
-
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
25
27
|
description:
|
26
28
|
email:
|
27
29
|
executables: []
|
@@ -42,21 +44,21 @@ rdoc_options: []
|
|
42
44
|
require_paths:
|
43
45
|
- lib
|
44
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
45
48
|
requirements:
|
46
49
|
- - ">="
|
47
50
|
- !ruby/object:Gem::Version
|
48
51
|
version: "0"
|
49
|
-
version:
|
50
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
51
54
|
requirements:
|
52
55
|
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: "0"
|
55
|
-
version:
|
56
58
|
requirements: []
|
57
59
|
|
58
60
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.5.2
|
60
62
|
signing_key:
|
61
63
|
specification_version: 3
|
62
64
|
summary: polyrex-objects
|