[Rails] type_for_columnメソッドから未使用のconnection引数を削除
背景
Active Recordの属性型システムにおいて、type_for_columnメソッドは以前までconnection引数を受け取っていましたが、過去のコミットでこの引数が不要になっていました。しかし、メソッドシグネチャはnilを受け入れる形で残されており、実際には使用されていない状態でした。今回のPRは、この不要な引数を削除してコードをクリーンアップするものです。
変更内容
メソッドシグネチャの変更
type_for_columnメソッドからconnection引数が削除されました。
変更前:
def type_for_column(connection, column)
type = column.cast_type
if immutable_strings_by_default && type.respond_to?(:to_immutable_string)
type.to_immutable_string
else
type
end
end
変更後:
def type_for_column(column)
type = column.cast_type
if immutable_strings_by_default && type.respond_to?(:to_immutable_string)
type.to_immutable_string
else
type
end
end
呼び出し側の修正
_default_attributesメソッド内での呼び出しも、第一引数のnilが削除されました。
変更前:
def _default_attributes
@default_attributes ||= begin
attributes_hash = columns_hash.transform_values do |column|
ActiveModel::Attribute.from_database(column.name, column.default, type_for_column(nil, column))
end
attribute_set = ActiveModel::AttributeSet.new(attributes_hash)
attribute_set.freeze
end
end
変更後:
def _default_attributes
@default_attributes ||= begin
attributes_hash = columns_hash.transform_values do |column|
ActiveModel::Attribute.from_database(column.name, column.default, type_for_column(column))
end
attribute_set = ActiveModel::AttributeSet.new(attributes_hash)
attribute_set.freeze
end
end
技術的な意義
この変更は以下の点でコードベースの品質を向上させます:
- メソッドシグネチャの明確化: 使用されない引数を削除することで、メソッドの意図がより明確になります
-
保守性の向上: 将来的に他の開発者が
connection引数の用途を調査する必要がなくなります - 一貫性の確保: #56484で行われた変更との整合性が取れます
この変更は内部実装の改善であり、Active Recordのパブリックインターフェースには影響を与えません。