mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #26282 from kamipo/add_type_default_value
Add `Type.default_value` and use it everywhere for internal
This commit is contained in:
commit
c14c0e3cf0
9 changed files with 13 additions and 15 deletions
|
@ -187,7 +187,7 @@ module ActiveRecord
|
|||
|
||||
class Null < Attribute # :nodoc:
|
||||
def initialize(name)
|
||||
super(name, nil, Type::Value.new)
|
||||
super(name, nil, Type.default_value)
|
||||
end
|
||||
|
||||
def type_cast(*)
|
||||
|
|
|
@ -437,7 +437,7 @@ module ActiveRecord
|
|||
|
||||
type_map.fetch(oid, fmod, sql_type) {
|
||||
warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
|
||||
Type::Value.new.tap do |cast_type|
|
||||
Type.default_value.tap do |cast_type|
|
||||
type_map.register_type(oid, cast_type)
|
||||
end
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ module ActiveRecord
|
|||
|
||||
def attribute_types # :nodoc:
|
||||
load_schema
|
||||
@attribute_types ||= Hash.new(Type::Value.new)
|
||||
@attribute_types ||= Hash.new(Type.default_value)
|
||||
end
|
||||
|
||||
def yaml_encoder # :nodoc:
|
||||
|
|
|
@ -312,7 +312,7 @@ module ActiveRecord
|
|||
key = group_columns.map { |aliaz, col_name|
|
||||
column = type_for(col_name) do
|
||||
calculated_data.column_types.fetch(aliaz) do
|
||||
Type::Value.new
|
||||
Type.default_value
|
||||
end
|
||||
end
|
||||
type_cast_calculated_value(row[aliaz], column)
|
||||
|
|
|
@ -80,14 +80,14 @@ module ActiveRecord
|
|||
limit_bind = Attribute.with_cast_value(
|
||||
"LIMIT".freeze,
|
||||
connection.sanitize_limit(limit_value),
|
||||
Type::Value.new,
|
||||
Type.default_value,
|
||||
)
|
||||
end
|
||||
if offset_value
|
||||
offset_bind = Attribute.with_cast_value(
|
||||
"OFFSET".freeze,
|
||||
offset_value.to_i,
|
||||
Type::Value.new,
|
||||
Type.default_value,
|
||||
)
|
||||
end
|
||||
connection.combine_bind_parameters(
|
||||
|
|
|
@ -32,8 +32,6 @@ module ActiveRecord
|
|||
class Result
|
||||
include Enumerable
|
||||
|
||||
IDENTITY_TYPE = Type::Value.new # :nodoc:
|
||||
|
||||
attr_reader :columns, :rows, :column_types
|
||||
|
||||
def initialize(columns, rows, column_types = {})
|
||||
|
@ -105,7 +103,7 @@ module ActiveRecord
|
|||
|
||||
def column_type(name, type_overrides = {})
|
||||
type_overrides.fetch(name) do
|
||||
column_types.fetch(name, IDENTITY_TYPE)
|
||||
column_types.fetch(name, Type.default_value)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ module ActiveRecord
|
|||
if klass
|
||||
klass.type_for_attribute(column_name.to_s)
|
||||
else
|
||||
Type::Value.new
|
||||
Type.default_value
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@ module ActiveRecord
|
|||
registry.lookup(*args, adapter: adapter, **kwargs)
|
||||
end
|
||||
|
||||
def default_value # :nodoc:
|
||||
@default_value ||= Value.new
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_adapter_name
|
||||
|
|
|
@ -11,7 +11,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def lookup(lookup_key, *args)
|
||||
fetch(lookup_key, *args) { default_value }
|
||||
fetch(lookup_key, *args) { Type.default_value }
|
||||
end
|
||||
|
||||
def fetch(lookup_key, *args, &block)
|
||||
|
@ -55,10 +55,6 @@ module ActiveRecord
|
|||
yield lookup_key, *args
|
||||
end
|
||||
end
|
||||
|
||||
def default_value
|
||||
@default_value ||= ActiveModel::Type::Value.new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue