lib/bindata/choice.rb
# Ensures that +params+ is of the form expected by #initialize.
Ensures that +params+ is of the form expected by #initialize.
Ensures that + params + is of the form expected by #initialize .
def sanitize_parameters!(sanitizer, params)
        if params.has_key?(:choices)
          choices = params[:choices]
          if ::Array === choices
            tmp = {}
            choices.each_with_index do |el, i|
              tmp[i] = el unless el.nil?
            end
            choices = tmp
          end
          if choices.has_key?(nil)
            raise ArgumentError, ":choices hash may not have nil key"
          end
          if choices.keys.detect { |k| Symbol === k }
            raise ArgumentError, ":choices hash may not have symbols for keys"
          end
          new_choices = {}
          choices.each_pair do |key, val|
            type, param = val
            klass = sanitizer.lookup_klass(type)
            sanitized_params = sanitizer.sanitize_params(klass, param)
            new_choices[key] = [klass, sanitized_params]
          end
          params[:choices] = new_choices
        end
        super(sanitizer, params)
      end
def sanitize_parameters! ( sanitizer , params ) if params . has_key? ( :choices ) choices = params [ :choices ] if :: Array === choices tmp = { } choices . each_with_index do | el , i | tmp [ i ] = el unless el . nil? end choices = tmp end if choices . has_key? ( nil ) raise ArgumentError , ":choices hash may not have nil key" end if choices . keys . detect { | k | Symbol === k } raise ArgumentError , ":choices hash may not have symbols for keys" end new_choices = { } choices . each_pair do | key , val | type , param = val klass = sanitizer . lookup_klass ( type ) sanitized_params = sanitizer . sanitize_params ( klass , param ) new_choices [ key ] = [ klass , sanitized_params ] end params [ :choices ] = new_choices end super ( sanitizer , params ) end
Ensures that +params+ is of the form expected by #initialize.
Ensures that + params + is of the form expected by #initialize .
# convert array to hash keyed by index # ensure valid hash keys # sanitize each choice
sanitizer
<not_specific>
params
<not_specific>