Sha256: 56e59b31fe21df8d207afed9c40c9118a59d98c781c1a0c0dd8fce46073229d8
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
module ActiveRecord module ConnectionAdapters class Mysql2Adapter alias __native_database_types_enum native_database_types def native_database_types #:nodoc types = __native_database_types_enum types[:enum] = { :name => "enum" } types end def columns(table_name, name = nil)#:nodoc: sql = "SHOW FIELDS FROM #{table_name}" columns = [] execute(sql, name).each { |field| columns << MysqlColumnWithEnum.new(field[0], field[4], field[1], field[2] == "YES") } columns end end class MysqlColumnWithEnum < Mysql2Column include ActiveRecordEnumerations::Column def initialize(name, default, sql_type = nil, null = true) if sql_type =~ /^enum/i values = sql_type.sub(/^enum\('([^)]+)'\)/i, '\1').split("','").map { |v| v.intern } default = default.intern if default and !default.empty? end super(name, default, sql_type, null, values) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
enum_column-0.1.6 | lib/enum_column/mysql2_adapter.rb |
enum_column-0.1.5 | lib/enum_column/mysql2_adapter.rb |
enum_column-0.1.4 | lib/enum_column/mysql2_adapter.rb |