Slide 53
Slide 53 text
module MetaSearch
module Utility #:nodoc:
!
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set
!
private
!
def preferred_method_name(method_id)
method_name = method_id.to_s
where = Where.new(method_name) rescue nil
return nil unless where
where.aliases.each do |a|
break if method_name.sub!(/#{a}(=?)$/, "#{where.name}\\1")
end
method_name
end
!
def array_of_strings?(o)
o.is_a?(Array) && o.all?{|obj| obj.is_a?(String)}
end
!
def array_of_arrays?(vals)
vals.is_a?(Array) && vals.first.is_a?(Array)
end
!
def array_of_dates?(vals)
vals.is_a?(Array) && vals.first.respond_to?(:to_time)
end
!
def cast_attributes(type, vals)
if array_of_arrays?(vals)
vals.map! {|v| cast_attributes(type, v)}
# Need to make sure not to kill multiparam dates/times
elsif vals.is_a?(Array) && (array_of_dates?(vals) || !(DATES+TIMES).include?(type))
vals.map! {|v| cast_attribute(type, v)}
else
cast_attribute(type, vals)