Module: ActiveRecord::Mysql::Enum

Defined in:
lib/active_record/mysql/enum.rb,
lib/active_record/mysql/enum/version.rb,
lib/active_record/mysql/enum/mysql_adapter.rb,
lib/active_record/mysql/enum/enum_column_adapter.rb

Defined Under Namespace

Modules: EnumColumnAdapter, MysqlAdapter Classes: Railtie

Constant Summary collapse

VERSION =
"2.4.2"
ActiveRecordMysqlAdapter =
Enum.mysql_adapter
ActiveRecordColumnWithEnums =
Enum.mysql_column_adapter

Class Method Summary collapse

Class Method Details

.initialize!Object



7
8
9
10
11
12
13
# File 'lib/active_record/mysql/enum.rb', line 7

def initialize!
  require 'active_record/mysql/enum/mysql_adapter'
  require 'active_record/mysql/enum/enum_type'
  require 'active_record/mysql/enum/enum_column_adapter'
  require 'active_record/mysql/enum/schema_definitions'
  require 'active_record/mysql/enum/validations'
end

.mysql_adapterObject



7
8
9
10
11
# File 'lib/active_record/mysql/enum/mysql_adapter.rb', line 7

def mysql_adapter
  defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter or raise "Could not find MySQL connection adapter"

  ActiveRecord::ConnectionAdapters::Mysql2Adapter
end

.mysql_column_adapterObject



11
12
13
14
15
16
17
18
19
# File 'lib/active_record/mysql/enum/enum_column_adapter.rb', line 11

def mysql_column_adapter
  if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column
    ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column
  elsif defined? ActiveRecord::ConnectionAdapters::MySQL::Column
    ActiveRecord::ConnectionAdapters::MySQL::Column
  else
    raise "could not find MySQL::Column or equivalent connection adapter"
  end
end

.register_enum_with_type_mapping(m) ⇒ Object



13
14
15
16
17
18
# File 'lib/active_record/mysql/enum/mysql_adapter.rb', line 13

def register_enum_with_type_mapping(m)
  m.register_type(/enum/i) do |sql_type|
    limit = sql_type.to_s.sub(/^enum\('(.+)'\)/i, '\1').split("','").map { |v| v.to_sym }
    ActiveRecord::Type::Enum.new(limit: limit)
  end
end