module ActiveRecordUuid::QuotingExtension

Public Instance Methods

quote(value, column = nil) click to toggle source
Calls superclass method
# File lib/active_record_uuid/extensions/quoting_extension.rb, line 6
def quote(value, column = nil)
  return super if column.blank? or !value.instance_of?(String) or value.bytesize != 36
  
  begin
    uuid = UUIDTools::UUID.parse(value)
  rescue ArgumentError, TypeError
    return super
  end

  case column.type
  when :binary
    "x'#{uuid.hexdigest}'"
  when :string
    case column.limit
    when 24
      "'#{Base64.encode64(uuid.raw).strip}'"
    when 32
      "'#{uuid.hexdigest}'"
    else
      "'#{uuid.to_s}'"
    end
  end
end