Sha256: c10d6d2e1fde614bc86f08151910f2400dcf368d9803a1f261f6d6782ca63ecd

Contents?: true

Size: 1 KB

Versions: 6

Compression:

Stored size: 1 KB

Contents

require 'active_record/connection_adapters/mysql2_adapter'

module ActiveRecord
  module ConnectionAdapters
    existing_class = defined?( Mysql2Adapter ) ? Mysql2Adapter : AbstractMysqlAdapter

    existing_class.class_eval do
      def native_database_types_with_enum
        native_database_types_without_enum.merge( :enum => { :name => "enum" }, :set => { :name => "set" } )
      end
      alias_method :native_database_types_without_enum, :native_database_types
      alias_method :native_database_types, :native_database_types_with_enum

      def type_to_sql_with_enum type, limit=nil, *args
        if type.to_s == "enum" || type.to_s == "set"
          "#{type}(#{quoted_comma_list limit})"
        else
          type_to_sql_without_enum type, limit, *args
        end
      end
      alias_method :type_to_sql_without_enum, :type_to_sql
      alias_method :type_to_sql, :type_to_sql_with_enum

      private
      def quoted_comma_list list
        list.to_a.map{|n| "'#{n}'"}.join(",")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
activerecord_enum-0.4.1 lib/connection_adapters/mysql2.rb
native_enum-1.0.0 lib/connection_adapters/mysql2.rb
native_enum-1.0.0pre1 lib/connection_adapters/mysql2.rb
activerecord_enum-0.4.0 lib/connection_adapters/mysql2.rb
activerecord_enum-0.3.0 lib/connection_adapters/mysql2.rb
activerecord_enum-0.2.0 lib/connection_adapters/mysql2.rb