lib/wash_out/param.rb in wash_out-0.8.4 vs lib/wash_out/param.rb in wash_out-0.9.0.beta.1

- old
+ new

@@ -8,33 +8,33 @@ attr_accessor :value attr_accessor :source_class # Defines a WSDL parameter with name +name+ and type specifier +type+. # The type specifier format is described in #parse_def. - def initialize(name, type, multiplied = false) + def initialize(soap_config, name, type, multiplied = false) type ||= {} - + @soap_config = soap_config @name = name.to_s @raw_name = name.to_s @map = {} @multiplied = multiplied - if WashOut::Engine.camelize_wsdl.to_s == 'lower' + if soap_config.camelize_wsdl.to_s == 'lower' @name = @name.camelize(:lower) - elsif WashOut::Engine.camelize_wsdl + 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(type.wash_out_param_map) + @map = self.class.parse_def(soap_config, type.wash_out_param_map) @source_class = type else @type = 'struct' - @map = self.class.parse_def(type) + @map = self.class.parse_def(soap_config, type) 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. @@ -48,25 +48,25 @@ if struct? data ||= {} if @multiplied data.map do |x| - map_struct x do |param, data, elem| - param.load(data, elem) + map_struct x do |param, dat, elem| + param.load(dat, elem) end end else - map_struct data do |param, data, elem| - param.load(data, elem) + map_struct data do |param, dat, elem| + param.load(dat, elem) end end else operation = case type when 'string'; :to_s when 'integer'; :to_i when 'double'; :to_f - when 'boolean'; lambda{|data| data === "0" ? false : !!data} + when 'boolean'; lambda{|dat| dat === "0" ? false : !!dat} when 'date'; :to_date when 'datetime'; :to_datetime when 'time'; :to_time else raise RuntimeError, "Invalid WashOut simple type: #{type}" end @@ -97,11 +97,11 @@ !source_class.nil? end def basic_type return name unless classified? - return source_class.wash_out_param_name + return source_class.wash_out_param_name(@soap_config) end def xsd_type return 'int' if type.to_s == 'integer' return 'dateTime' if type.to_s == 'datetime' @@ -127,11 +127,11 @@ # with the +name+ set to "value". # If a WashOut::Param instance is passed as a +nested_type+, the corresponding # +:parameter_name+ is ignored. # # This function returns an array of WashOut::Param objects. - def self.parse_def(definition) + 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 @@ -144,21 +144,21 @@ 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(name, opt[0], true) + WashOut::Param.new(soap_config, name, opt[0], true) else - WashOut::Param.new(name, opt) + WashOut::Param.new(soap_config, name, opt) end end else raise RuntimeError, "Wrong definition: #{definition.inspect}" end end def flat_copy - copy = self.class.new(@name, @type.to_sym, @multiplied) + copy = self.class.new(@soap_config, @name, @type.to_sym, @multiplied) copy.raw_name = raw_name copy end private