def type_cast_code(var_name)
if collection?
case type
when :string then "#{self.class.name}.hash_to_string_collection(#{var_name})"
when :text then "#{self.class.name}.hash_to_string_collection(#{var_name})"
when :integer then "#{self.class.name}.hash_to_integer_collection(#{var_name})"
when :float then "#{self.class.name}.hash_to_float_collection(#{var_name})"
when :decimal then "#{self.class.name}.hash_to_decimal_collection(#{var_name})"
when :datetime then "#{self.class.name}.hash_to_time_collection(#{var_name})"
when :timestamp then "#{self.class.name}.hash_to_time_collection(#{var_name})"
when :time then "#{self.class.name}.hash_to_dummy_time_collection(#{var_name})"
when :date then "#{self.class.name}.hash_to_date_collection(#{var_name})"
when :binary then "#{self.class.name}.hash_to_string_collection(#{var_name})"
when :boolean then "#{self.class.name}.hash_to_boolean_collection(#{var_name})"
when :map then nil
when :object then nil
else nil
end
else
case type
when :string then nil
when :text then nil
when :integer then "(#{var_name}.to_i rescue #{var_name} ? 1 : 0)"
when :float then "#{var_name}.to_f"
when :decimal then "#{self.class.name}.value_to_decimal(#{var_name})"
when :datetime then "#{self.class.name}.string_to_time(#{var_name})"
when :timestamp then "#{self.class.name}.string_to_time(#{var_name})"
when :time then "#{self.class.name}.value_to_dummy_time(#{var_name})"
when :date then "#{self.class.name}.string_to_date(#{var_name})"
when :binary then "#{self.class.name}.binary_to_string(#{var_name})"
when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})"
when :map then nil
when :object then nil
else nil
end
end
end