soybean 2.5.3 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.1.0)
4
+ activesupport (3.1.3)
5
5
  multi_json (~> 1.0)
6
6
  diff-lcs (1.1.3)
7
7
  git (1.2.5)
@@ -12,10 +12,10 @@ GEM
12
12
  rake
13
13
  multi_json (1.0.3)
14
14
  nokogiri (1.5.0)
15
- rack (1.3.4)
15
+ rack (1.3.5)
16
16
  rack-mount (0.8.3)
17
17
  rack (>= 1.0.0)
18
- rake (0.9.2)
18
+ rake (0.9.2.2)
19
19
  rspec (2.3.0)
20
20
  rspec-core (~> 2.3.0)
21
21
  rspec-expectations (~> 2.3.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.4
@@ -28,4 +28,7 @@ module Soybean
28
28
  mattr_accessor :logger
29
29
  self.logger = Logger.new(STDOUT)
30
30
 
31
+ mattr_accessor :cache
32
+ self.cache = Hash.new { |hash, key| hash[key] = { } }
33
+
31
34
  end
@@ -27,7 +27,6 @@ class Soybean::CLI < Thor
27
27
  full_path = File.expand_path wsdl, FileUtils.pwd
28
28
  if File.directory? full_path
29
29
  Dir["#{full_path}/*.wsdl"].each do |file|
30
- puts file.inspect
31
30
  generate_service(file, dir, opts)
32
31
  end
33
32
  else
@@ -42,6 +41,7 @@ class Soybean::CLI < Thor
42
41
 
43
42
  no_tasks do
44
43
  def generate_service(wsdl, dir, options)
44
+ Soybean.cache.clear
45
45
  Soybean::Generators::ServiceGenerator.new(dir, wsdl, spec_dir(dir)).generate do |filename, content, generator|
46
46
  opts = options
47
47
  if generator.is_a? Soybean::Generators::ModelGenerator
@@ -30,7 +30,7 @@ module Soybean
30
30
  def init_from_array(arry)
31
31
  check_arguments_number! arry
32
32
  attributes.each_with_index do |key, i|
33
- self.send "#{key}=".to_sym, arry.at(i)
33
+ self.send :"#{key}=", arry.at(i)
34
34
  end
35
35
  end
36
36
 
@@ -18,7 +18,9 @@ module Soybean
18
18
  @wsdl.importedschema.map do |uri, schema|
19
19
  "require 'mappings/#{URI.parse(schema.targetnamespace).path[1..-2].underscore}'\n"
20
20
  end.join +
21
- "class #{class_name} < #{interface_name}\nend"
21
+ "class #{class_name} < #{interface_name}" +
22
+ "include #{URI.parse(@wsdl.importedschema.values.last.targetnamespace).path[1..-2].camelize}"
23
+ "end"
22
24
  end
23
25
 
24
26
  def class_name
@@ -2,7 +2,7 @@ module Soybean
2
2
  module Generators
3
3
  class TypesGenerator < WSDL::SOAP::ClassDefCreator
4
4
  class_attribute :classes_cache, :instance_reader => true, :instance_writer => true
5
- self.classes_cache = {}
5
+ self.classes_cache = Soybean.cache[:classes]
6
6
  include BaseGenerator
7
7
 
8
8
  attr_reader :name
@@ -51,7 +51,7 @@ module Soybean
51
51
 
52
52
  def with_cache
53
53
  result = yield
54
- if !classes_cache.key?(result.name) && result
54
+ if result && !classes_cache.key?(result.name)
55
55
  classes_cache[result.name] = true
56
56
  result.dump
57
57
  end
@@ -1,5 +1,8 @@
1
1
  module Soybean
2
2
  class Interface
3
+ include ActiveSupport::Callbacks
4
+ NO_ACTIONS = [:endpoint]
5
+
3
6
  class_attribute :interfaces, :instance_reader => false, :instance_writer => false
4
7
 
5
8
  def self.inherited(subclass)
@@ -8,11 +11,14 @@ module Soybean
8
11
  Soybean.services << subclass if subclass.superclass < Soybean::Interface
9
12
  end
10
13
 
11
- def self.actions
12
- self.instance_methods - Object.instance_methods
14
+ def self.actions(implemented=true)
15
+ if implemented
16
+ self.public_instance_methods(false) - NO_ACTIONS
17
+ else
18
+ self::Methods.map(&:second).map(&:to_sym)
19
+ end
13
20
  end
14
21
 
15
-
16
22
  attr_reader :logger
17
23
 
18
24
  def initialize(logger=Soybean.logger)
@@ -9,24 +9,19 @@ module Soybean
9
9
  private
10
10
 
11
11
  def dump_entry(regname, var)
12
- if @cache.key?(var[:class])
13
- ''
14
- else
15
- @cache[var[:class]] = true
16
- "#{regname}.register(\n " +
17
- [
18
- dump_entry_item(var, :class),
19
- dump_entry_item(var, :soap_class),
20
- dump_entry_item(var, :schema_name, :qname),
21
- dump_entry_item(var, :schema_type, :qname),
22
- dump_entry_item(var, :is_anonymous),
23
- dump_entry_item(var, :schema_basetype, :qname),
24
- dump_entry_item(var, :schema_qualified),
25
- dump_entry_item(var, :schema_element),
26
- dump_entry_item(var, :schema_attribute)
27
- ].compact.join(",\n ") +
28
- "\n)\n"
29
- end
12
+ "#{regname}.register(\n " +
13
+ [
14
+ dump_entry_item(var, :class),
15
+ dump_entry_item(var, :soap_class),
16
+ dump_entry_item(var, :schema_name, :qname),
17
+ dump_entry_item(var, :schema_type, :qname),
18
+ dump_entry_item(var, :is_anonymous),
19
+ dump_entry_item(var, :schema_basetype, :qname),
20
+ dump_entry_item(var, :schema_qualified),
21
+ dump_entry_item(var, :schema_element),
22
+ dump_entry_item(var, :schema_attribute)
23
+ ].compact.join(",\n ") +
24
+ "\n)\n"
30
25
  end
31
26
  end
32
27
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{soybean}
8
- s.version = "2.5.3"
8
+ s.version = "2.5.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anton Sozontov"]
12
- s.date = %q{2011-10-27}
12
+ s.date = %q{2011-11-21}
13
13
  s.default_executable = %q{soybean}
14
14
  s.description = %q{Generate soap web-services from you wsdl. Generate: all classes from xsd, and other.}
15
15
  s.email = %q{a.sozontov@gmail.com}
@@ -15,353 +15,353 @@ require 'xsd/namedelements'
15
15
 
16
16
 
17
17
  module SOAP
18
- module Mapping
18
+ module Mapping
19
19
 
20
20
 
21
- class LiteralRegistry
22
- include RegistrySupport
21
+ class LiteralRegistry
22
+ include RegistrySupport
23
23
 
24
- attr_accessor :excn_handler_obj2soap
25
- attr_accessor :excn_handler_soap2obj
24
+ attr_accessor :excn_handler_obj2soap
25
+ attr_accessor :excn_handler_soap2obj
26
26
 
27
- def initialize
28
- super()
29
- @excn_handler_obj2soap = nil
30
- @excn_handler_soap2obj = nil
31
- end
32
-
33
- def obj2soap(obj, qname, obj_class = nil)
34
- soap_obj = nil
35
- if obj.is_a?(SOAPElement)
36
- soap_obj = obj
37
- else
38
- soap_obj = any2soap(obj, qname, obj_class)
39
- end
40
- return soap_obj if soap_obj
41
- if @excn_handler_obj2soap
42
- soap_obj = @excn_handler_obj2soap.call(obj) { |yield_obj|
43
- Mapping.obj2soap(yield_obj, nil, nil, MAPPING_OPT)
44
- }
45
- return soap_obj if soap_obj
46
- end
47
- raise MappingError.new("cannot map #{obj.class.name} as #{qname}")
48
- end
49
-
50
- # node should be a SOAPElement
51
- def soap2obj(node, obj_class = nil)
52
- cause = nil
53
- begin
54
- return any2obj(node, obj_class)
55
- rescue MappingError
56
- cause = $!
57
- end
58
- if @excn_handler_soap2obj
59
- begin
60
- return @excn_handler_soap2obj.call(node) { |yield_node|
61
- Mapping.soap2obj(yield_node, nil, nil, MAPPING_OPT)
62
- }
63
- rescue Exception
27
+ def initialize
28
+ super()
29
+ @excn_handler_obj2soap = nil
30
+ @excn_handler_soap2obj = nil
64
31
  end
65
- end
66
- raise MappingError.new("cannot map #{node.elename.name}/#{node.type.name} to Ruby object", cause)
67
- end
68
32
 
69
- private
33
+ def obj2soap(obj, qname, obj_class = nil)
34
+ soap_obj = nil
35
+ if obj.is_a?(SOAPElement)
36
+ soap_obj = obj
37
+ else
38
+ soap_obj = any2soap(obj, qname, obj_class)
39
+ end
40
+ return soap_obj if soap_obj
41
+ if @excn_handler_obj2soap
42
+ soap_obj = @excn_handler_obj2soap.call(obj) { |yield_obj|
43
+ Mapping.obj2soap(yield_obj, nil, nil, MAPPING_OPT)
44
+ }
45
+ return soap_obj if soap_obj
46
+ end
47
+ raise MappingError.new("cannot map #{obj.class.name} as #{qname}")
48
+ end
70
49
 
71
- MAPPING_OPT = { :no_reference => true }
50
+ # node should be a SOAPElement
51
+ def soap2obj(node, obj_class = nil)
52
+ cause = nil
53
+ begin
54
+ return any2obj(node, obj_class)
55
+ rescue MappingError
56
+ cause = $!
57
+ end
58
+ if @excn_handler_soap2obj
59
+ begin
60
+ return @excn_handler_soap2obj.call(node) { |yield_node|
61
+ Mapping.soap2obj(yield_node, nil, nil, MAPPING_OPT)
62
+ }
63
+ rescue Exception
64
+ end
65
+ end
66
+ raise MappingError.new("cannot map #{node.elename.name}/#{node.type.name} to Ruby object", cause)
67
+ end
72
68
 
73
- def definedobj2soap(obj, definition)
74
- obj2soap(obj, definition.elename, definition.mapped_class)
75
- end
69
+ private
76
70
 
77
- def any2soap(obj, qname, obj_class)
78
- ele = nil
79
- if obj.is_a?(SOAP::Mapping::Object)
80
- return mappingobj2soap(obj, qname)
81
- end
82
- class_definition = schema_definition_from_class(obj.class)
83
- if class_definition.nil? and obj_class
84
- class_definition = schema_definition_from_class(obj_class)
85
- end
86
- elename_definition = schema_definition_from_elename(qname)
87
- if !class_definition and !elename_definition
88
- # no definition found
89
- return anyobj2soap(obj, qname)
90
- end
91
- if !class_definition or !elename_definition
92
- # use found one
93
- return stubobj2soap(obj, qname, class_definition || elename_definition)
94
- end
95
- # found both:
96
- if class_definition.class_for == elename_definition.class_for
97
- # if two definitions are for the same class, give qname a priority.
98
- return stubobj2soap(obj, qname, elename_definition)
99
- end
100
- # it should be a derived class
101
- return stubobj2soap(obj, qname, class_definition)
102
- end
71
+ MAPPING_OPT = { :no_reference => true }
103
72
 
104
- def anyobj2soap(obj, qname)
105
- ele = nil
106
- case obj
107
- when Hash
108
- ele = SOAPElement.from_obj(obj, nil)
109
- ele.elename = qname
110
- when Array
111
- # treat as a list of simpletype
112
- ele = SOAPElement.new(qname, obj.join(" "))
113
- when XSD::QName
114
- ele = SOAPElement.new(qname)
115
- ele.text = obj
116
- else
117
- # expected to be a basetype or an anyType.
118
- # SOAPStruct, etc. is used instead of SOAPElement.
119
- begin
120
- ele = Mapping.obj2soap(obj, nil, nil, MAPPING_OPT)
121
- ele.elename = qname
122
- rescue MappingError
123
- ele = SOAPElement.new(qname, obj.to_s)
73
+ def definedobj2soap(obj, definition)
74
+ obj2soap(obj, definition.elename, definition.mapped_class)
124
75
  end
125
- end
126
- add_attributes2soap(obj, ele)
127
- ele
128
- end
129
76
 
130
- def stubobj2soap(obj, qname, definition)
131
- if obj.nil?
132
- ele = SOAPNil.new
133
- ele.elename = qname
134
- elsif obj.is_a?(::String)
135
- ele = SOAPElement.new(qname, obj)
136
- else
137
- ele = SOAPElement.new(qname)
138
- end
139
- ele.qualified = definition.qualified
140
- if definition.type
141
- ele.type = definition.type
142
- if definition.basetype or Mapping.root_type_hint
143
- Mapping.reset_root_type_hint
144
- ele.force_typed = true
77
+ def any2soap(obj, qname, obj_class)
78
+ ele = nil
79
+ if obj.is_a?(SOAP::Mapping::Object)
80
+ return mappingobj2soap(obj, qname)
81
+ end
82
+ class_definition = schema_definition_from_class(obj.class)
83
+ if class_definition.nil? and obj_class
84
+ class_definition = schema_definition_from_class(obj_class)
85
+ end
86
+ elename_definition = schema_definition_from_elename(qname)
87
+ if !class_definition and !elename_definition
88
+ # no definition found
89
+ return anyobj2soap(obj, qname)
90
+ end
91
+ if !class_definition or !elename_definition
92
+ # use found one
93
+ return stubobj2soap(obj, qname, class_definition || elename_definition)
94
+ end
95
+ # found both:
96
+ if class_definition.class_for == elename_definition.class_for
97
+ # if two definitions are for the same class, give qname a priority.
98
+ return stubobj2soap(obj, qname, elename_definition)
99
+ end
100
+ # it should be a derived class
101
+ return stubobj2soap(obj, qname, class_definition)
145
102
  end
146
- end
147
- if qname.nil? and definition.elename
148
- ele.elename = definition.elename
149
- end
150
- return ele if obj.nil?
151
- stubobj2soap_elements(obj, ele, definition.elements)
152
- add_definedattributes2soap(obj, ele, definition)
153
- ele
154
- end
155
103
 
156
- def stubobj2soap_elements(obj, ele, definition, is_choice = false)
157
- added = false
158
- case definition
159
- when SchemaSequenceDefinition, SchemaEmptyDefinition
160
- definition.each do |eledef|
161
- ele_added = stubobj2soap_elements(obj, ele, eledef, is_choice)
162
- added = true if ele_added
163
- end
164
- when SchemaChoiceDefinition
165
- definition.each do |eledef|
166
- added = stubobj2soap_elements(obj, ele, eledef, true)
167
- break if added
104
+ def anyobj2soap(obj, qname)
105
+ ele = nil
106
+ case obj
107
+ when Hash
108
+ ele = SOAPElement.from_obj(obj, nil)
109
+ ele.elename = qname
110
+ when Array
111
+ # treat as a list of simpletype
112
+ ele = SOAPElement.new(qname, obj.join(" "))
113
+ when XSD::QName
114
+ ele = SOAPElement.new(qname)
115
+ ele.text = obj
116
+ else
117
+ # expected to be a basetype or an anyType.
118
+ # SOAPStruct, etc. is used instead of SOAPElement.
119
+ begin
120
+ ele = Mapping.obj2soap(obj, nil, nil, MAPPING_OPT)
121
+ ele.elename = qname
122
+ rescue MappingError
123
+ ele = SOAPElement.new(qname, obj.to_s)
124
+ end
125
+ end
126
+ add_attributes2soap(obj, ele)
127
+ ele
168
128
  end
169
- else
170
- added = true
171
- if definition.as_any?
172
- any = Mapping.get_attributes_for_any(obj)
173
- SOAPElement.from_objs(any).each do |child|
174
- ele.add(child)
175
- end
176
- elsif obj.respond_to?(:each) and definition.as_array?
177
- obj.each do |item|
178
- ele.add(definedobj2soap(item, definition))
179
- end
180
- else
181
- child = Mapping.get_attribute(obj, definition.varname)
182
- if child.nil? and (is_choice or definition.minoccurs == 0)
183
- added = false
129
+
130
+ def stubobj2soap(obj, qname, definition)
131
+ if obj.nil?
132
+ ele = SOAPNil.new
133
+ ele.elename = qname
134
+ elsif obj.is_a?(::String)
135
+ ele = SOAPElement.new(qname, obj)
184
136
  else
185
- if child.respond_to?(:each) and definition.as_array?
186
- if child.empty?
187
- added = false
188
- else
189
- child.each do |item|
137
+ ele = SOAPElement.new(qname)
138
+ end
139
+ ele.qualified = definition.qualified
140
+ if definition.type
141
+ ele.type = definition.type
142
+ if definition.basetype or Mapping.root_type_hint
143
+ Mapping.reset_root_type_hint
144
+ ele.force_typed = true
145
+ end
146
+ end
147
+ if qname.nil? and definition.elename
148
+ ele.elename = definition.elename
149
+ end
150
+ return ele if obj.nil?
151
+ stubobj2soap_elements(obj, ele, definition.elements)
152
+ add_definedattributes2soap(obj, ele, definition)
153
+ ele
154
+ end
155
+
156
+ def stubobj2soap_elements(obj, ele, definition, is_choice = false)
157
+ added = false
158
+ case definition
159
+ when SchemaSequenceDefinition, SchemaEmptyDefinition
160
+ definition.each do |eledef|
161
+ ele_added = stubobj2soap_elements(obj, ele, eledef, is_choice)
162
+ added = true if ele_added
163
+ end
164
+ when SchemaChoiceDefinition
165
+ definition.each do |eledef|
166
+ added = stubobj2soap_elements(obj, ele, eledef, true)
167
+ break if added
168
+ end
169
+ else
170
+ added = true
171
+ if definition.as_any?
172
+ any = Mapping.get_attributes_for_any(obj)
173
+ SOAPElement.from_objs(any).each do |child|
174
+ ele.add(child)
175
+ end
176
+ elsif obj.respond_to?(:each) and definition.as_array?
177
+ obj.each do |item|
190
178
  ele.add(definedobj2soap(item, definition))
191
179
  end
180
+ else
181
+ child = Mapping.get_attribute(obj, definition.varname)
182
+ if child.nil? and (is_choice or definition.minoccurs == 0)
183
+ added = false
184
+ else
185
+ if child.respond_to?(:each) and definition.as_array?
186
+ if child.empty?
187
+ added = false
188
+ else
189
+ child.each do |item|
190
+ ele.add(definedobj2soap(item, definition))
191
+ end
192
+ end
193
+ else
194
+ ele.add(definedobj2soap(child, definition))
195
+ end
196
+ end
197
+ end
198
+ end
199
+ added
200
+ end
201
+
202
+ def mappingobj2soap(obj, qname)
203
+ ele = SOAPElement.new(qname)
204
+ obj.__xmlele.each do |key, value|
205
+ if value.is_a?(::Array)
206
+ value.each do |item|
207
+ ele.add(obj2soap(item, key))
192
208
  end
193
209
  else
194
- ele.add(definedobj2soap(child, definition))
210
+ ele.add(obj2soap(value, key))
195
211
  end
196
212
  end
213
+ obj.__xmlattr.each do |key, value|
214
+ ele.extraattr[key] = value
215
+ end
216
+ ele
197
217
  end
198
- end
199
- added
200
- end
201
218
 
202
- def mappingobj2soap(obj, qname)
203
- ele = SOAPElement.new(qname)
204
- obj.__xmlele.each do |key, value|
205
- if value.is_a?(::Array)
206
- value.each do |item|
207
- ele.add(obj2soap(item, key))
219
+ def any2obj(node, obj_class = nil)
220
+ is_compound = node.is_a?(::SOAP::SOAPCompoundtype)
221
+ # trust xsi:type first
222
+ if is_compound and node.type
223
+ definition = schema_definition_from_type(node.type)
224
+ end
225
+ # element name next
226
+ definition ||= schema_definition_from_elename(node.elename)
227
+ # class defined in parent type last
228
+ if obj_class
229
+ definition ||= schema_definition_from_class(obj_class)
230
+ end
231
+ if definition
232
+ obj_class = definition.class_for
233
+ end
234
+ if is_compound
235
+ if definition
236
+ return elesoap2stubobj(node, obj_class, definition)
237
+ elsif node.is_a?(::SOAP::SOAPNameAccessible)
238
+ return elesoap2plainobj(node)
239
+ end
208
240
  end
209
- else
210
- ele.add(obj2soap(value, key))
241
+ obj = Mapping.soap2obj(node, nil, obj_class, MAPPING_OPT)
242
+ add_attributes2obj(node, obj)
243
+ obj
211
244
  end
212
- end
213
- obj.__xmlattr.each do |key, value|
214
- ele.extraattr[key] = value
215
- end
216
- ele
217
- end
218
245
 
219
- def any2obj(node, obj_class = nil)
220
- is_compound = node.is_a?(::SOAP::SOAPCompoundtype)
221
- # trust xsi:type first
222
- if is_compound and node.type
223
- definition = schema_definition_from_type(node.type)
224
- end
225
- # element name next
226
- definition ||= schema_definition_from_elename(node.elename)
227
- # class defined in parent type last
228
- if obj_class
229
- definition ||= schema_definition_from_class(obj_class)
230
- end
231
- if definition
232
- obj_class = definition.class_for
233
- end
234
- if is_compound
235
- if definition
236
- return elesoap2stubobj(node, obj_class, definition)
237
- elsif node.is_a?(::SOAP::SOAPNameAccessible)
238
- return elesoap2plainobj(node)
246
+ def elesoap2stubobj(node, obj_class, definition)
247
+ obj = nil
248
+ if obj_class == ::String
249
+ obj = node.text
250
+ elsif obj_class < ::String and node.respond_to?(:text)
251
+ obj = obj_class.new(node.text)
252
+ else
253
+ obj = Mapping.create_empty_object(obj_class)
254
+ add_elesoap2stubobj(node, obj, definition)
255
+ end
256
+ add_attributes2stubobj(node, obj, definition)
257
+ obj
239
258
  end
240
- end
241
- obj = Mapping.soap2obj(node, nil, obj_class, MAPPING_OPT)
242
- add_attributes2obj(node, obj)
243
- obj
244
- end
245
-
246
- def elesoap2stubobj(node, obj_class, definition)
247
- obj = nil
248
- if obj_class == ::String
249
- obj = node.text
250
- elsif obj_class < ::String and node.respond_to?(:text)
251
- obj = obj_class.new(node.text)
252
- else
253
- obj = Mapping.create_empty_object(obj_class)
254
- add_elesoap2stubobj(node, obj, definition)
255
- end
256
- add_attributes2stubobj(node, obj, definition)
257
- obj
258
- end
259
-
260
- def elesoap2plainobj(node)
261
- obj = nil
262
- if !node.have_member
263
- obj = base2obj(node, ::SOAP::SOAPString)
264
- else
265
- obj = anytype2obj(node)
266
- add_elesoap2plainobj(node, obj)
267
- end
268
- add_attributes2obj(node, obj)
269
- obj
270
- end
271
259
 
272
- def anytype2obj(node)
273
- if node.is_a?(::SOAP::SOAPBasetype)
274
- return node.data
275
- end
276
- ::SOAP::Mapping::Object.new
277
- end
278
-
279
- def add_elesoap2stubobj(node, obj, definition)
280
- vars = {}
281
- node.each do |name, value|
282
- item = definition.elements.find_element(value.elename)
283
- if item
284
- child = elesoapchild2obj(value, item)
285
- else
286
- # unknown element is treated as anyType.
287
- child = any2obj(value)
260
+ def elesoap2plainobj(node)
261
+ obj = nil
262
+ if !node.have_member
263
+ obj = base2obj(node, ::SOAP::SOAPString)
264
+ else
265
+ obj = anytype2obj(node)
266
+ add_elesoap2plainobj(node, obj)
267
+ end
268
+ add_attributes2obj(node, obj)
269
+ obj
288
270
  end
289
- if item and item.as_array?
290
- (vars[name] ||= []) << child
291
- elsif vars.key?(name)
292
- vars[name] = [vars[name], child].flatten
293
- else
294
- vars[name] = child
271
+
272
+ def anytype2obj(node)
273
+ if node.is_a?(::SOAP::SOAPBasetype)
274
+ return node.data
275
+ end
276
+ ::SOAP::Mapping::Object.new
295
277
  end
296
- end
297
- if obj.is_a?(::Array) and is_stubobj_elements_for_array(vars)
298
- Array.instance_method(:replace).bind(obj).call(vars.values[0])
299
- else
300
- Mapping.set_attributes(obj, vars)
301
- end
302
- end
303
278
 
304
- def elesoapchild2obj(value, eledef)
305
- if eledef.mapped_class
306
- if eledef.mapped_class.include?(::SOAP::SOAPBasetype)
307
- base2obj(value, eledef.mapped_class)
308
- else
309
- any2obj(value, eledef.mapped_class)
279
+ def add_elesoap2stubobj(node, obj, definition)
280
+ vars = { }
281
+ node.each do |name, value|
282
+ item = definition.elements.find_element(value.elename)
283
+ if item
284
+ child = elesoapchild2obj(value, item)
285
+ else
286
+ # unknown element is treated as anyType.
287
+ child = any2obj(value)
288
+ end
289
+ if item and item.as_array?
290
+ (vars[name] ||= []) << child
291
+ elsif vars.key?(name)
292
+ vars[name] = [vars[name], child].flatten
293
+ else
294
+ vars[name] = child
295
+ end
296
+ end
297
+ if obj.is_a?(::Array) and is_stubobj_elements_for_array(vars)
298
+ Array.instance_method(:replace).bind(obj).call(vars.values[0])
299
+ else
300
+ Mapping.set_attributes(obj, vars)
301
+ end
310
302
  end
311
- else
312
- child_definition = schema_definition_from_elename(eledef.elename)
313
- if child_definition
314
- any2obj(value, child_definition.class_for)
315
- else
316
- # untyped element is treated as anyType.
317
- any2obj(value)
303
+
304
+ def elesoapchild2obj(value, eledef)
305
+ if eledef.mapped_class
306
+ if eledef.mapped_class.include?(::SOAP::SOAPBasetype)
307
+ base2obj(value, eledef.mapped_class)
308
+ else
309
+ any2obj(value, eledef.mapped_class)
310
+ end
311
+ else
312
+ child_definition = schema_definition_from_elename(eledef.elename)
313
+ if child_definition
314
+ any2obj(value, child_definition.class_for)
315
+ else
316
+ # untyped element is treated as anyType.
317
+ any2obj(value)
318
+ end
319
+ end
318
320
  end
319
- end
320
- end
321
321
 
322
- def add_attributes2stubobj(node, obj, definition)
323
- return if obj.nil? or node.extraattr.empty?
324
- if attributes = definition.attributes
325
- define_xmlattr(obj)
326
- attributes.each do |qname, class_name|
327
- child = node.extraattr[qname]
328
- next if child.nil?
329
- if class_name
330
- klass = Mapping.class_from_name(class_name)
331
- if klass.include?(::SOAP::SOAPBasetype)
332
- child = klass.to_data(child)
322
+ def add_attributes2stubobj(node, obj, definition)
323
+ return if obj.nil? or node.extraattr.empty?
324
+ if attributes = definition.attributes
325
+ define_xmlattr(obj)
326
+ attributes.each do |qname, class_name|
327
+ child = node.extraattr[qname]
328
+ next if child.nil?
329
+ if class_name
330
+ klass = Mapping.class_from_name(class_name)
331
+ if klass.include?(::SOAP::SOAPBasetype)
332
+ child = klass.to_data(child)
333
+ end
334
+ end
335
+ obj.__xmlattr[qname] = child
336
+ define_xmlattr_accessor(obj, qname)
333
337
  end
334
338
  end
335
- obj.__xmlattr[qname] = child
336
- define_xmlattr_accessor(obj, qname)
337
339
  end
338
- end
339
- end
340
340
 
341
- def add_elesoap2plainobj(node, obj)
342
- node.each do |name, value|
343
- obj.__add_xmlele_value(value.elename, any2obj(value))
344
- end
345
- end
341
+ def add_elesoap2plainobj(node, obj)
342
+ node.each do |name, value|
343
+ obj.__add_xmlele_value(value.elename, any2obj(value))
344
+ end
345
+ end
346
346
 
347
- def add_attributes2obj(node, obj)
348
- return if obj.nil? or node.extraattr.empty?
349
- define_xmlattr(obj)
350
- node.extraattr.each do |qname, value|
351
- obj.__xmlattr[qname] = value
352
- define_xmlattr_accessor(obj, qname)
353
- end
354
- end
347
+ def add_attributes2obj(node, obj)
348
+ return if obj.nil? or node.extraattr.empty?
349
+ define_xmlattr(obj)
350
+ node.extraattr.each do |qname, value|
351
+ obj.__xmlattr[qname] = value
352
+ define_xmlattr_accessor(obj, qname)
353
+ end
354
+ end
355
355
 
356
- # Mapping.define_attr_accessor calls define_method with proc and it exhausts
357
- # much memory for each singleton Object. just instance_eval instead of it.
358
- def define_xmlattr_accessor(obj, qname)
359
- # untaint depends GenSupport.safemethodname
360
- name = Mapping.safemethodname('xmlattr_' + qname.name).untaint
361
- unless obj.respond_to?(name)
362
- # untaint depends QName#dump
363
- qnamedump = qname.dump.untaint
364
- obj.instance_eval <<-EOS
356
+ # Mapping.define_attr_accessor calls define_method with proc and it exhausts
357
+ # much memory for each singleton Object. just instance_eval instead of it.
358
+ def define_xmlattr_accessor(obj, qname)
359
+ # untaint depends GenSupport.safemethodname
360
+ name = Mapping.safemethodname('xmlattr_' + qname.name).untaint
361
+ unless obj.respond_to?(name)
362
+ # untaint depends QName#dump
363
+ qnamedump = qname.dump.untaint
364
+ obj.instance_eval <<-EOS
365
365
  def #{name}
366
366
  @__xmlattr[#{qnamedump}]
367
367
  end
@@ -369,24 +369,24 @@ private
369
369
  def #{name}=(value)
370
370
  @__xmlattr[#{qnamedump}] = value
371
371
  end
372
- EOS
373
- end
374
- end
372
+ EOS
373
+ end
374
+ end
375
375
 
376
- # Mapping.define_attr_accessor calls define_method with proc and it exhausts
377
- # much memory for each singleton Object. just instance_eval instead of it.
378
- def define_xmlattr(obj)
379
- obj.instance_variable_set('@__xmlattr', {})
380
- unless obj.respond_to?(:__xmlattr)
381
- obj.instance_eval <<-EOS
376
+ # Mapping.define_attr_accessor calls define_method with proc and it exhausts
377
+ # much memory for each singleton Object. just instance_eval instead of it.
378
+ def define_xmlattr(obj)
379
+ obj.instance_variable_set('@__xmlattr', { })
380
+ unless obj.respond_to?(:__xmlattr)
381
+ obj.instance_eval <<-EOS
382
382
  def __xmlattr
383
383
  @__xmlattr
384
384
  end
385
- EOS
385
+ EOS
386
+ end
387
+ end
386
388
  end
387
- end
388
- end
389
389
 
390
390
 
391
- end
391
+ end
392
392
  end
@@ -43,7 +43,7 @@ class SimpleRestriction < Info
43
43
  @fixed = {}
44
44
  @attributes = XSD::NamedElements.new
45
45
  end
46
-
46
+
47
47
  def valid?(value)
48
48
  return false unless check_restriction(value)
49
49
  return false unless check_length(value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soybean
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-27 00:00:00.000000000 +04:00
12
+ date: 2011-11-21 00:00:00.000000000 +04:00
13
13
  default_executable: soybean
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
17
- requirement: &8481240 !ruby/object:Gem::Requirement
17
+ requirement: &12398920 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *8481240
25
+ version_requirements: *12398920
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &8475500 !ruby/object:Gem::Requirement
28
+ requirement: &12397860 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *8475500
36
+ version_requirements: *12397860
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &8471340 !ruby/object:Gem::Requirement
39
+ requirement: &12397140 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *8471340
47
+ version_requirements: *12397140
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: nokogiri
50
- requirement: &8469360 !ruby/object:Gem::Requirement
50
+ requirement: &12370980 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *8469360
58
+ version_requirements: *12370980
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rack
61
- requirement: &8453180 !ruby/object:Gem::Requirement
61
+ requirement: &12367140 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *8453180
69
+ version_requirements: *12367140
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rack-mount
72
- requirement: &8451880 !ruby/object:Gem::Requirement
72
+ requirement: &12364940 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *8451880
80
+ version_requirements: *12364940
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rspec
83
- requirement: &8450920 !ruby/object:Gem::Requirement
83
+ requirement: &12337740 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 2.3.0
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *8450920
91
+ version_requirements: *12337740
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: yard
94
- requirement: &8449660 !ruby/object:Gem::Requirement
94
+ requirement: &12336620 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 0.6.0
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *8449660
102
+ version_requirements: *12336620
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: bundler
105
- requirement: &8448460 !ruby/object:Gem::Requirement
105
+ requirement: &12335580 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 1.0.0
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *8448460
113
+ version_requirements: *12335580
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: jeweler
116
- requirement: &8446940 !ruby/object:Gem::Requirement
116
+ requirement: &12334660 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,7 +121,7 @@ dependencies:
121
121
  version: 1.6.4
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *8446940
124
+ version_requirements: *12334660
125
125
  description: ! 'Generate soap web-services from you wsdl. Generate: all classes from
126
126
  xsd, and other.'
127
127
  email: a.sozontov@gmail.com
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  segments:
346
346
  - 0
347
- hash: 2457752307248948752
347
+ hash: -555538828332696193
348
348
  required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  none: false
350
350
  requirements: