Skip to content
Browse files

initialization fix and some refactoring to reduce files count

  • Loading branch information...
1 parent b94264a commit cef02e890bc8a606d8f167c66c358ef10fc0c270 @electronick committed Sep 16, 2011
Showing with 22 additions and 52 deletions.
  1. +1 −3 init.rb
  2. +3 −3 lib/enum/enum_adapter.rb
  3. +0 −15 lib/enum/jdbcmysql_adapter.rb
  4. +14 −12 lib/enum/mysql_adapter.rb
  5. +4 −19 lib/enum_column.rb
View
4 init.rb
@@ -1,3 +1 @@
-require File.dirname(__FILE__) + "/rails/init.rb"
-pp '111'
-pp defined? Mysql
+require File.dirname(__FILE__) + "/rails/init.rb"
View
6 lib/enum/enum_adapter.rb
@@ -2,10 +2,10 @@
# This module provides all the column helper methods to deal with the
# values and adds the common type management code for the adapters.
-column_class = if defined? ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
- ActiveRecord::ConnectionAdapters::MysqlColumn
-else
+column_class = if defined? ActiveRecord::ConnectionAdapters::Mysql2Column
ActiveRecord::ConnectionAdapters::Mysql2Column
+else
+ ActiveRecord::ConnectionAdapters::MysqlColumn
end
column_class.module_eval do
View
15 lib/enum/jdbcmysql_adapter.rb
@@ -1,15 +0,0 @@
-module ActiveRecord
- module ConnectionAdapters
- class MySQLJdbcConnection
- alias __native_database_types_enum native_database_types
-
- def native_database_types #:nodoc
- types = __native_database_types_enum
- types[:enum] = { :name => "enum" }
- types
- end
-
- end
-
- end
-end
View
26 lib/enum/mysql_adapter.rb
@@ -1,15 +1,17 @@
-module ActiveRecord
- module ConnectionAdapters
- class Mysql2Adapter
- alias __native_database_types_enum native_database_types
+adapter_class = if defined? ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
+ ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
+elsif defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter
+elsif defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
+ ActiveRecord::ConnectionAdapters::MysqlAdapter
+end
- def native_database_types #:nodoc
- types = __native_database_types_enum
- types[:enum] = { :name => "enum" }
- types
- end
+adapter_class.module_eval do
+ alias __native_database_types_enum native_database_types
- end
-
+ def native_database_types #:nodoc
+ types = __native_database_types_enum
+ types[:enum] = { :name => "enum" }
+ types
end
-end
+end
View
23 lib/enum_column.rb
@@ -1,16 +1,8 @@
-class Railtie < Rails::Railtie
- initializer "enum_column.initialize" do |app|
+if defined?(::Rails::Railtie)
+ class EnumColumnRailtie < Rails::Railtie
ActiveSupport.on_load :active_record do
+ require 'enum/mysql_adapter'
require 'enum/enum_adapter'
- #require 'enum/mysql_adapter' #if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
- if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
- if defined? ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
- #we are using JRuby
- require 'enum/jdbcmysql_adapter'
- else
- require 'enum/mysql_adapter'
- end
- end
require 'enum/schema_statements'
require 'enum/schema_definitions'
require 'enum/quoting'
@@ -21,11 +13,4 @@ class Railtie < Rails::Railtie
require 'enum/active_record_helper'
end
end
-end
-
-
-
-
-
-
-
+end

0 comments on commit cef02e8

Please sign in to comment.
Something went wrong with that request. Please try again.