aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-29 12:25:15 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-29 12:43:39 +0100
commit4fcd847c8d9fb2b22e1c2e3c840c8d1c590b56b4 (patch)
tree18ea251b7cabf02fe381ff4a121452f23d76ce2a
parent5766539342426e956980bf6f54ef99600cbfc33e (diff)
downloadrails-4fcd847c8d9fb2b22e1c2e3c840c8d1c590b56b4.tar.gz
rails-4fcd847c8d9fb2b22e1c2e3c840c8d1c590b56b4.tar.bz2
rails-4fcd847c8d9fb2b22e1c2e3c840c8d1c590b56b4.zip
Extract simplified_type into the abstract class
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb19
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb18
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb10
3 files changed, 24 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 72cf490d7e..548ca83353 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -3,7 +3,7 @@ require 'active_support/core_ext/object/blank'
module ActiveRecord
module ConnectionAdapters
class AbstractMysqlAdapter < AbstractAdapter
- class Column < ConnectionAdapters::Column
+ class Column < ConnectionAdapters::Column # :nodoc:
def extract_default(default)
if sql_type =~ /blob/i || type == :text
if default.blank?
@@ -23,8 +23,25 @@ module ActiveRecord
super
end
+ # Must return the relevant concrete adapter
+ def adapter
+ raise NotImplementedError
+ end
+
private
+ def simplified_type(field_type)
+ return :boolean if adapter.emulate_booleans && field_type.downcase.index("tinyint(1)")
+
+ case field_type
+ when /enum/i, /set/i then :string
+ when /year/i then :integer
+ when /bit/i then :binary
+ else
+ super
+ end
+ end
+
def extract_limit(sql_type)
case sql_type
when /blob|text/i
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 00d9caa8ee..8b574518e5 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -21,22 +21,10 @@ module ActiveRecord
module ConnectionAdapters
class Mysql2Adapter < AbstractMysqlAdapter
- class Column < AbstractMysqlAdapter::Column # :nodoc:
- BOOL = "tinyint(1)"
-
- private
-
- # FIXME: Combine with the mysql version and move to abstract adapter
- def simplified_type(field_type)
- return :boolean if Mysql2Adapter.emulate_booleans && field_type.downcase.index(BOOL)
- case field_type
- when /enum/i, /set/i then :string
- when /year/i then :integer
- when /bit/i then :binary
- else
- super
- end
+ class Column < AbstractMysqlAdapter::Column # :nodoc:
+ def adapter
+ Mysql2Adapter
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index d61875195a..182db65165 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -59,6 +59,7 @@ module ActiveRecord
# * <tt>:sslcipher</tt> - Necessary to use MySQL with an SSL connection.
#
class MysqlAdapter < AbstractMysqlAdapter
+
class Column < AbstractMysqlAdapter::Column #:nodoc:
def self.string_to_time(value)
return super unless Mysql::Time === value
@@ -82,13 +83,8 @@ module ActiveRecord
new_date(v.year, v.month, v.day)
end
- private
-
- # FIXME: Combine with the mysql2 version and move to abstract adapter
- def simplified_type(field_type)
- return :boolean if MysqlAdapter.emulate_booleans && field_type.downcase.index("tinyint(1)")
- return :string if field_type =~ /enum/i
- super
+ def adapter
+ MysqlAdapter
end
end