Skip to content

Instantly share code, notes, and snippets.

@ndnenkov
Created June 30, 2016 07:10
Show Gist options
  • Save ndnenkov/34c90ad827d3fa25b89483c8a1f31cb5 to your computer and use it in GitHub Desktop.
Save ndnenkov/34c90ad827d3fa25b89483c8a1f31cb5 to your computer and use it in GitHub Desktop.
module ActiveRecord
module ConnectionAdapters
class Column
private
def simplified_type(field_type)
case field_type
when /\bint(?:eger)?\b/i
:integer
when /\b(?:float|double)\b/i
:float
when /\b(?:decimal|numeric|number)\b/i
extract_scale(field_type) == 0 ? :integer : :decimal
when /\bdatetime\b/i
:datetime
when /\btimestamp\b/i
:timestamp
when /\btime\b/i
:time
when /\bdate\b/i
:date
when /\bclob\b/i, /\btext\b/i
:text
when /\bblob\b/i, /\bbinary\b/i
:binary
when /\bchar\b/i, /\bstring\b/i
:string
when /\bboolean\b/i
:boolean
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment