提交 560bf1c9 编写于 作者: R Ryuta Kamizono

Extract `MySQL::TypeMetadata` class to `connection_adapters/mysql/type_metadata.rb`

上级 83026cb1
......@@ -3,6 +3,7 @@
require 'active_record/connection_adapters/mysql/schema_creation'
require 'active_record/connection_adapters/mysql/schema_definitions'
require 'active_record/connection_adapters/mysql/schema_dumper'
require 'active_record/connection_adapters/mysql/type_metadata'
require 'active_support/core_ext/string/strip'
......@@ -20,33 +21,6 @@ def schema_creation
MySQL::SchemaCreation.new(self)
end
class MysqlTypeMetadata < DelegateClass(SqlTypeMetadata) # :nodoc:
attr_reader :extra, :strict
def initialize(type_metadata, extra: "", strict: false)
super(type_metadata)
@type_metadata = type_metadata
@extra = extra
@strict = strict
end
def ==(other)
other.is_a?(MysqlTypeMetadata) &&
attributes_for_hash == other.attributes_for_hash
end
alias eql? ==
def hash
attributes_for_hash.hash
end
protected
def attributes_for_hash
[self.class, @type_metadata, extra, strict]
end
end
##
# :singleton-method:
# By default, the Mysql2Adapter will consider all columns of type <tt>tinyint(1)</tt>
......@@ -804,7 +778,7 @@ def extract_precision(sql_type)
end
def fetch_type_metadata(sql_type, extra = "")
MysqlTypeMetadata.new(super(sql_type), extra: extra, strict: strict_mode?)
MySQL::TypeMetadata.new(super(sql_type), extra: extra, strict: strict_mode?)
end
def add_index_length(option_strings, column_names, options = {})
......
module ActiveRecord
module ConnectionAdapters
module MySQL
class TypeMetadata < DelegateClass(SqlTypeMetadata) # :nodoc:
attr_reader :extra, :strict
def initialize(type_metadata, extra: "", strict: false)
super(type_metadata)
@type_metadata = type_metadata
@extra = extra
@strict = strict
end
def ==(other)
other.is_a?(MySQL::TypeMetadata) &&
attributes_for_hash == other.attributes_for_hash
end
alias eql? ==
def hash
attributes_for_hash.hash
end
protected
def attributes_for_hash
[self.class, @type_metadata, extra, strict]
end
end
end
end
end
......@@ -64,7 +64,7 @@ def test_should_not_set_default_for_blob_and_text_data_types
MySQL::Column.new("title", "a", SqlTypeMetadata.new(sql_type: "blob"))
end
text_type = AbstractMysqlAdapter::MysqlTypeMetadata.new(
text_type = MySQL::TypeMetadata.new(
SqlTypeMetadata.new(type: :text))
assert_raise ArgumentError do
MySQL::Column.new("title", "Hello", text_type)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册