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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bc9482fde51072a9e13af95b9ad729f5fbd1a8f
4
- data.tar.gz: f5cb08673251968132944f9fda23489ccbe22728
3
+ metadata.gz: d06a5b8d9fa6ddadaf9f2293ce65ed07c22e0d2d
4
+ data.tar.gz: c8a635cf6570fc68b1a15e54a7765279a3247dbc
5
5
  SHA512:
6
- metadata.gz: 59732cbdae2fd29bc567c250028dd94fef953a9508d67902a3ee10e76a76af8b14a04dc7363db1bd0ace147371104a9a7bedb39ee4a446d5a4a414475d0a0584
7
- data.tar.gz: 94bfab5b487f512fbd93cf66de2c190b0bc7737c3986c1395ae1319ac2692ba87eefb59630b9236234b4e3e1ed763d7661fd843e15fd5ca0f09845226dc6db8a
6
+ metadata.gz: 7def32cabec4f6634064638be39a5eb872e56a23d8d95ebab0904daa8c3ca5350b7915cdb04b1685fce334d0244fa72a92ad07716800d9758613884a97217dfa
7
+ data.tar.gz: d16b6325fe8b98fafa1e61aae27c168dadb3afab527dd552f7b0385565beb57d8bb8873f5930cd6d19b1a5f4ebf7fd3e98f3d2b92e52ab667136efc8eaff166e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,35 +2,50 @@
2
2
 
3
3
  # file: polyrex-createobject.rb
4
4
 
5
- require 'polyrex-schema'
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
- @schema = schema
20
+ raise "missing schema" unless schema
17
21
 
18
- if @schema then
19
- a = @schema.split('/')
20
- @rpaths = (a.length).times.inject({}) do |r|
21
- r.merge ({a.join('/').gsub(/\[[^\]]+\]/,'') => a.pop})
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
- values = @rpaths.values.reverse
32
+ self.instance_eval " def #{@obj.name.downcase}(h, id=@@id, &blk)
25
33
 
26
- @rpaths.keys.reverse.each.with_index do |key,i |
27
- @rpaths[key] = values[i..-1].join('/')
28
- end
34
+ new_parent = create_node(@parent_node, @schema, h, id).element('records')
29
35
 
30
- names = @rpaths.to_a[0..-2].map {|k,v| [v[/[^\[]+/], k]}
36
+ obj = @obj.new
37
+ obj.record = new_parent
38
+ obj.instance_variable_set(:@schema, @schema[/\\/(.*$)/,1])
31
39
 
32
- attach_create_handlers(names)
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
- def attach_create_handlers(names)
44
- methodx = names[0..-2].map do |name, xpath|
58
+ private
45
59
 
46
- # nested records
47
- %Q(
48
- def #{name}(params={}, id=nil,&blk)
60
+ def attach_create_handlers(a)
49
61
 
50
- id ||= @@id
51
- orig_parent = @parent_node
52
- new_parent = create_node(@parent_node, @rpaths['#{xpath}'], params, id).element('records')
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
- if block_given? then
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
- self.record = orig_parent
69
+ buffer = PolyrexSchema.new(child_schema[/^[^\/]+/]).to_s
70
+ record = Rexle.new buffer
60
71
 
61
- self
62
- end
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
- name, xpath = names[-1]
82
+ record.root.add_attribute({'id' => @@id.to_s.clone})
83
+
84
+ a = child_schema[/[^\[]+(?=\])/].split(',')
67
85
 
68
- # top record
69
- methodx << %Q(
70
- def #{name}(params={}, id=nil,&blk)
71
- id ||= @@id
72
- orig_parent = @parent_node
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
- self
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 create_node(parent_node, child_schema, params={}, id=nil)
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
- def xpath_to_rpath(xpath)
118
- xpath.split('/').each_slice(2).map(&:last).join('/').gsub(/\[[^\]]+\]/,'')
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.15
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
- MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTEzMDIwNjIxMDA0NloXDTE0MDIwNjIxMDA0NlowSDESMB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: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: '0'
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: '0'
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: '0'
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.1.11
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