class BinData::ChoiceArgProcessor
def choices_as_hash(choices)
def choices_as_hash(choices) if choices.respond_to?(:to_ary) key_array_by_index(choices.to_ary) else choices end end
def ensure_valid_keys(choices)
def ensure_valid_keys(choices) if choices.key?(nil) raise ArgumentError, ":choices hash may not have nil key" end if choices.keys.detect { |key| key.is_a?(Symbol) && key != :default } raise ArgumentError, ":choices hash may not have symbols for keys" end end
def key_array_by_index(array)
def key_array_by_index(array) result = {} array.each_with_index do |el, i| result[i] = el unless el.nil? end result end
def sanitize_parameters!(obj_class, params) #:nodoc:
def sanitize_parameters!(obj_class, params) #:nodoc: params.merge!(obj_class.dsl_params) params.sanitize_choices(:choices) do |choices| hash_choices = choices_as_hash(choices) ensure_valid_keys(hash_choices) hash_choices end end