polyrex-createobject 0.5.0 → 0.5.1

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: 858ae60261940e950c402b8c96c10894ffee4c30
4
- data.tar.gz: 3bfbed1dd66c9a945f9ad07d63902d03ba94a632
3
+ metadata.gz: 9e20a75456b2321ccb733f539cefc23d9c84952c
4
+ data.tar.gz: b9324027feb7cb1721163f4d922b906302c4b6c7
5
5
  SHA512:
6
- metadata.gz: 080fdfa97fab4c4adcdb8c5611cddc47fd6c8ad2e7bd02eab5a111addeab64719f69f994e138179758aaae4099ee28060fa64db742c2b739593cf5fb8bf05a33
7
- data.tar.gz: 6959be849a09a9a4a2219285d6f18950b7cf7a767fdf330756b01fd9c0950848c7f46d7a5d29fe696e5b2d180a75e60452b3d9d1f0d003fbf5f596187ec8be37
6
+ metadata.gz: f65b8663f71586026030076b26c40916bf44e52bf3b0c51fb546c0388808696496cd8b4a904d733a889fcfff90daa081dd772c932b65e28e2b343607fa8f3375
7
+ data.tar.gz: 5df50d34eb25ac11fcf1072c62208927361ae2be1085d4d0031c77f0509f8f77f18db1e9dc5637d477246d41bc4100ee9ea1a6821455067c7c29439792d0efb0
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- s��-�ke��M�����݁���y�/s )b��D�י�p��G�}��"-����$���{��9m�����+K�����A&iSjr/����SȠ�BQD^�oq«��룐�,H��$',�)(VP u$vI9�zo��o!y�'8�1�w���l�K#���n�C��Q�i�����Yテ���&���568˘��`$O5���Μ�6<i�C}*Æ@~ЬV��m���MU��'O��
1
+ Tfc��M�֔.m�!�� l;4B�/�?�/����ÄLaj�-�a�����SxSzxZC"��<�c
2
+ �7�[��d�5d���73k����W���Q�-��)�p�4�NT������~Ǽk,�������;�aܿ��c�� e��� 7 "�$6i�0�J����>5j�<����T�4뼶��2E�U�O��.B���8|g��8��������|�4<� X�DO��o��M�to��q� G}I7��s
@@ -37,7 +37,6 @@ class PolyrexCreateObject
37
37
  obj.record = new_parent
38
38
  obj.instance_variable_set(:@schema, @schema[/\\/(.*$)/,1])
39
39
 
40
-
41
40
  if block_given? then
42
41
  blk.call obj
43
42
  else
@@ -59,8 +58,14 @@ class PolyrexCreateObject
59
58
 
60
59
  def attach_create_handlers(a)
61
60
 
61
+ #return if PolyrexCreateObject
62
62
  class_name = "root".capitalize
63
- parent_klass = Object.const_set(class_name,Class.new)
63
+ parent_klass = if ObjectSpace.each_object(Class)\
64
+ .to_a.map(&:name).include? 'Root' then
65
+ Root
66
+ else
67
+ parent_klass = Object.const_set(class_name,Class.new)
68
+ end
64
69
  result = scan parent_klass, a
65
70
  end
66
71
 
@@ -95,7 +100,7 @@ class PolyrexCreateObject
95
100
 
96
101
  def scan(parent, list)
97
102
 
98
- record = list.shift
103
+ cname = list.shift
99
104
  args = list
100
105
 
101
106
  r = []
@@ -103,46 +108,53 @@ class PolyrexCreateObject
103
108
  fields = []
104
109
  fields << args.shift while args.first.is_a? Symbol
105
110
 
106
- class_name = record.capitalize
107
- klass = Object.const_set(class_name,Class.new)
111
+ class_name = cname.capitalize
108
112
 
109
- parent.class_eval do
113
+ klass = if ObjectSpace.each_object(Class)\
114
+ .to_a.map(&:name).include? class_name.to_s then
115
+ Object.const_get class_name
116
+ else
117
+ Object.const_set(class_name,Class.new)
118
+ end
110
119
 
111
- define_method :create_node do |parent_node, child_schema, params={}, id=nil|
120
+ parent.class_eval do
112
121
 
113
- buffer = PolyrexSchema.new(child_schema[/^[^\/]+/]).to_s
114
- record = Rexle.new buffer
122
+ define_method :create_node do |parent_node, child_schema,
123
+ params={}, id=nil|
115
124
 
116
- if id then
117
- @@id.succ!
118
- else
119
- if @@id.to_i.to_s == @@id.to_s then
120
- @@id.succ!
121
- else
122
- @@id = @parent_node.element('count(//@id)').to_i + 2
123
- end
124
- end
125
+ buffer = PolyrexSchema.new(child_schema[/^[^\/]+/]).to_s
126
+ record = Rexle.new buffer
125
127
 
126
- record.root.add_attribute({'id' => @@id.to_s.clone})
128
+ if id then
129
+ @@id.succ!
130
+ else
131
+ if @@id.to_i.to_s == @@id.to_s then
132
+ @@id.succ!
133
+ else
134
+ @@id = @parent_node.element('count(//@id)').to_i + 2
135
+ end
136
+ end
127
137
 
128
- a = child_schema[/[^\[]+(?=\])/].split(',')
138
+ record.root.add_attribute({'id' => @@id.to_s.clone})
129
139
 
130
- summary = record.root.element('summary')
131
- a.each do |field_name|
132
- field = summary.element(field_name.strip)
133
- field.text = params[field_name.strip.to_sym]
134
- end
140
+ a = child_schema[/[^\[]+(?=\])/].split(',')
135
141
 
136
- parent_node.add record.root
142
+ summary = record.root.element('summary')
143
+ a.each do |field_name|
144
+ field = summary.element(field_name.strip)
145
+ field.text = params[field_name.strip.to_sym]
146
+ end
137
147
 
138
- end
148
+ parent_node.add record.root
139
149
 
150
+ end # end of define_method :create_node
140
151
 
141
- define_method record do |h, id=nil, &blk|
152
+ define_method cname do |h, id=nil, &blk|
142
153
 
143
154
  id ||= @@id
144
- local_schema = "%s[%s]" % [record, fields.join(',')]
145
- new_parent = create_node(@parent_node, local_schema, h, id).element('records')
155
+ local_schema = "%s[%s]" % [cname, fields.join(',')]
156
+ new_parent = create_node(@parent_node, local_schema, h, id)\
157
+ .element('records')
146
158
 
147
159
  obj = klass.new
148
160
 
@@ -167,6 +179,7 @@ class PolyrexCreateObject
167
179
  next_rec = args.shift
168
180
 
169
181
  if next_rec.first.is_a? Array then
182
+
170
183
  remaining = scan(parent, *args) unless args.length < 1
171
184
 
172
185
  next_rec.each do |x|
@@ -182,8 +195,8 @@ class PolyrexCreateObject
182
195
  id ||= @@id
183
196
  local_schema = "%s[%s]" % [record, fields.join(',')]
184
197
 
185
- new_parent = create_node(@parent_node, local_schema, params, id).element('records')
186
-
198
+ new_parent = create_node(@parent_node, local_schema,
199
+ params, id).element('records')
187
200
  obj = remaining.new
188
201
  obj.record = new_parent
189
202
  yield obj
@@ -195,6 +208,7 @@ class PolyrexCreateObject
195
208
  end
196
209
 
197
210
  else
211
+
198
212
  remaining = scan(klass, *list) unless args.length < 1
199
213
  scan(klass, next_rec)
200
214
  scan(r, remaining) if remaining
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  f3O5lCaUfMDZbRHRyvXjy/4PFRQKLr6ZLbpQN+dWceS6/82/5xWEL/7Bo/86R5xN
32
32
  JL6pGH//inbMWQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-06-11 00:00:00.000000000 Z
34
+ date: 2014-06-22 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: polyrex-schema
metadata.gz.sig CHANGED
Binary file