lib/wash_out/param.rb in wash_out-0.9.2 vs lib/wash_out/param.rb in wash_out-0.10.0.beta.1
- old
+ new
@@ -11,38 +11,34 @@
# Defines a WSDL parameter with name +name+ and type specifier +type+.
# The type specifier format is described in #parse_def.
def initialize(soap_config, name, type, multiplied = false)
type ||= {}
@soap_config = soap_config
- @name = name.to_s
+ @name = WashOut.normalize(name, soap_config)
@raw_name = name.to_s
@map = {}
@multiplied = multiplied
- if soap_config.camelize_wsdl.to_s == 'lower'
- @name = @name.camelize(:lower)
- elsif soap_config.camelize_wsdl
- @name = @name.camelize
- end
-
if type.is_a?(Symbol)
@type = type.to_s
elsif type.is_a?(Class)
@type = 'struct'
@map = self.class.parse_def(soap_config, type.wash_out_param_map)
@source_class = type
- else
+ elsif type.is_a?(Hash)
@type = 'struct'
@map = self.class.parse_def(soap_config, type)
+ else
+ raise RuntimeError, "Wrong definition: #{type.inspect}"
end
end
# Converts a generic externally derived Ruby value, such as String or
# Hash, to a native Ruby object according to the definition of this type.
def load(data, key)
if !data.has_key? key
- raise WashOut::Dispatcher::SOAPError, "Required SOAP parameter '#{key}' is missing"
+ raise WashOut::SOAPError, "Required SOAP parameter '#{key}' is missing"
end
data = data[key]
data = [data] if @multiplied && !data.is_a?(Array)
@@ -82,11 +78,11 @@
data.send(operation)
else
operation.call(data)
end
rescue
- raise WashOut::Dispatcher::SOAPError, "Invalid SOAP parameter '#{key}' format"
+ raise WashOut::SOAPError, "Invalid SOAP parameter '#{key}' format"
end
end
end
# Checks if this Param defines a complex type.
@@ -132,45 +128,34 @@
# This function returns an array of WashOut::Param objects.
def self.parse_def(soap_config, definition)
raise RuntimeError, "[] should not be used in your params. Use nil if you want to mark empty set." if definition == []
return [] if definition == nil
- if definition.is_a?(Class) && definition.ancestors.include?(WashOut::Type)
- definition = definition.wash_out_param_map
- end
+ definition = { :value => definition } unless definition.is_a?(Hash)
- if [Array, Symbol].include?(definition.class)
- definition = { :value => definition }
- end
-
- if definition.is_a? Hash
- definition.map do |name, opt|
- if opt.is_a? WashOut::Param
- opt
- elsif opt.is_a? Array
- WashOut::Param.new(soap_config, name, opt[0], true)
- else
- WashOut::Param.new(soap_config, name, opt)
- end
+ definition.map do |name, opt|
+ if opt.is_a? WashOut::Param
+ opt
+ elsif opt.is_a? Array
+ WashOut::Param.new(soap_config, name, opt[0], true)
+ else
+ WashOut::Param.new(soap_config, name, opt)
end
- else
- raise RuntimeError, "Wrong definition: #{definition.inspect}"
end
end
def flat_copy
copy = self.class.new(@soap_config, @name, @type.to_sym, @multiplied)
copy.raw_name = raw_name
- copy.source_class = copy.source_class
copy
end
private
# Used to load an entire structure.
def map_struct(data)
unless data.is_a?(Hash)
- raise WashOut::Dispatcher::SOAPError, "SOAP message structure is broken"
+ raise WashOut::SOAPError, "SOAP message structure is broken"
end
data = data.with_indifferent_access
struct = {}.with_indifferent_access