diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-02-17 11:29:51 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-02-17 13:28:48 -0700 |
commit | 4a3cb840b0c992b0f15b66274dfa7de71a38fa03 (patch) | |
tree | 12911fe78b638c8328b8c882f02d3d0c35c29134 /activerecord/lib | |
parent | b3fdf9c596e4821e0028472b9c2740fd4d6655c8 (diff) | |
download | rails-4a3cb840b0c992b0f15b66274dfa7de71a38fa03.tar.gz rails-4a3cb840b0c992b0f15b66274dfa7de71a38fa03.tar.bz2 rails-4a3cb840b0c992b0f15b66274dfa7de71a38fa03.zip |
`Type#type_cast_from_database` -> `Type#deserialize`
Diffstat (limited to 'activerecord/lib')
20 files changed, 27 insertions, 27 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb index 91886f1324..419513fee1 100644 --- a/activerecord/lib/active_record/attribute.rb +++ b/activerecord/lib/active_record/attribute.rb @@ -108,7 +108,7 @@ module ActiveRecord class FromDatabase < Attribute # :nodoc: def type_cast(value) - type.type_cast_from_database(value) + type.deserialize(value) end end diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index 90c36e4b02..f6a9fff343 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -2,7 +2,7 @@ module ActiveRecord module AttributeMethods module TimeZoneConversion class TimeZoneConverter < DelegateClass(Type::Value) # :nodoc: - def type_cast_from_database(value) + def deserialize(value) convert_time_to_time_zone(super) end diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index 87d4bc8578..f259bfe728 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -102,7 +102,7 @@ module ActiveRecord # # Users may also define their own custom types, as long as they respond # to the methods defined on the value type. The method - # +type_cast_from_database+ or +type_cast_from_user+ will be called on + # +deserialize+ or +type_cast_from_user+ will be called on # your type object, with raw input from the database or from your # controllers. See ActiveRecord::Type::Value for the expected API. It is # recommended that your type objects inherit from an existing type, or @@ -143,7 +143,7 @@ module ActiveRecord # @currency_converter = currency_converter # end # - # # value will be the result of +type_cast_from_database+ or + # # value will be the result of +deserialize+ or # # +type_cast_from_user+. Assumed to be in instance of +Money+ in # # this case. # def type_cast_for_database(value) @@ -195,7 +195,7 @@ module ActiveRecord # Otherwise, the default will be +nil+. # # +user_provided_default+ Whether the default value should be cast using - # +type_cast_from_user+ or +type_cast_from_database+. + # +type_cast_from_user+ or +deserialize+. def define_attribute( name, cast_type, diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb index 932aaf7aa7..af7ef7cbaa 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb @@ -47,7 +47,7 @@ module ActiveRecord def schema_default(column) type = lookup_cast_type_from_column(column) - default = type.type_cast_from_database(column.default) + default = type.deserialize(column.default) unless default.nil? type.type_cast_for_schema(default) end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb index 2608a2abab..deb2ea50a3 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb @@ -25,9 +25,9 @@ module ActiveRecord @delimiter = delimiter end - def type_cast_from_database(value) + def deserialize(value) if value.is_a?(::String) - type_cast_array(parse_pg_array(value), :type_cast_from_database) + type_cast_array(parse_pg_array(value), :deserialize) else super end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb index 6bd1b8ecae..8f9d6e7f9b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb @@ -3,7 +3,7 @@ module ActiveRecord module PostgreSQL module OID # :nodoc: class Bytea < Type::Binary # :nodoc: - def type_cast_from_database(value) + def deserialize(value) return if value.nil? return value.to_s if value.is_a?(Type::Binary::Data) PGconn.unescape_bytea(super) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb index b46e50c865..40bec8a3bf 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb @@ -9,7 +9,7 @@ module ActiveRecord :hstore end - def type_cast_from_database(value) + def deserialize(value) if value.is_a?(::String) ::Hash[value.scan(HstorePair).map { |k, v| v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb index 13dd037314..27cc00b722 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb @@ -9,7 +9,7 @@ module ActiveRecord :json end - def type_cast_from_database(value) + def deserialize(value) if value.is_a?(::String) ::ActiveSupport::JSON.decode(value) rescue nil else diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb index 380c50fc14..c761494a00 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb @@ -13,7 +13,7 @@ module ActiveRecord # the comparison here. Therefore, we need to parse and re-dump the # raw value here to ensure the insignificant whitespaces are # consistent with our encoder's output. - raw_old_value = type_cast_for_database(type_cast_from_database(raw_old_value)) + raw_old_value = type_cast_for_database(deserialize(raw_old_value)) super(raw_old_value, new_value) end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb index 9d3633d109..c4d7aaaba5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb @@ -49,7 +49,7 @@ module ActiveRecord private def type_cast_single(value) - infinity?(value) ? value : @subtype.type_cast_from_database(value) + infinity?(value) ? value : @subtype.deserialize(value) end def type_cast_single_for_database(value) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb index 97b4fd3d08..98ab5fc667 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb @@ -5,7 +5,7 @@ module ActiveRecord class Uuid < Type::Value # :nodoc: ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x - alias_method :type_cast_for_database, :type_cast_from_database + alias_method :type_cast_for_database, :deserialize def type :uuid diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 470e0b5d29..22b52c7347 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -105,7 +105,7 @@ module ActiveRecord end end - def type_cast_from_database(value) + def deserialize(value) return if value.nil? mapping.key(value.to_i) end diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index c5b10fcddf..a58d8355aa 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -185,7 +185,7 @@ module ActiveRecord end class LockingType < DelegateClass(Type::Value) # :nodoc: - def type_cast_from_database(value) + def deserialize(value) # `nil` *should* be changed to 0 super.to_i end diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 63e0d2fc21..4a4de86d48 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -353,9 +353,9 @@ module ActiveRecord def type_cast_calculated_value(value, type, operation = nil) case operation when 'count' then value.to_i - when 'sum' then type.type_cast_from_database(value || 0) + when 'sum' then type.deserialize(value || 0) when 'average' then value.respond_to?(:to_d) ? value.to_d : value - else type.type_cast_from_database(value) + else type.deserialize(value) end end diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb index 3a3e65ef32..500c478e65 100644 --- a/activerecord/lib/active_record/result.rb +++ b/activerecord/lib/active_record/result.rb @@ -81,7 +81,7 @@ module ActiveRecord def cast_values(type_overrides = {}) # :nodoc: types = columns.map { |name| column_type(name, type_overrides) } result = rows.map do |values| - types.zip(values).map { |type, value| type.type_cast_from_database(value) } + types.zip(values).map { |type, value| type.deserialize(value) } end columns.one? ? result.map!(&:first) : result diff --git a/activerecord/lib/active_record/type/binary.rb b/activerecord/lib/active_record/type/binary.rb index 005a48ef0d..412d387c76 100644 --- a/activerecord/lib/active_record/type/binary.rb +++ b/activerecord/lib/active_record/type/binary.rb @@ -23,7 +23,7 @@ module ActiveRecord end def changed_in_place?(raw_old_value, value) - old_value = type_cast_from_database(raw_old_value) + old_value = deserialize(raw_old_value) old_value != value end diff --git a/activerecord/lib/active_record/type/helpers/mutable.rb b/activerecord/lib/active_record/type/helpers/mutable.rb index dc37f4a885..9af39aa9fb 100644 --- a/activerecord/lib/active_record/type/helpers/mutable.rb +++ b/activerecord/lib/active_record/type/helpers/mutable.rb @@ -3,7 +3,7 @@ module ActiveRecord module Helpers module Mutable # :nodoc: def type_cast_from_user(value) - type_cast_from_database(type_cast_for_database(value)) + deserialize(type_cast_for_database(value)) end # +raw_old_value+ will be the `_before_type_cast` version of the diff --git a/activerecord/lib/active_record/type/integer.rb b/activerecord/lib/active_record/type/integer.rb index 2ab2402dfd..b8cbf6114d 100644 --- a/activerecord/lib/active_record/type/integer.rb +++ b/activerecord/lib/active_record/type/integer.rb @@ -16,7 +16,7 @@ module ActiveRecord :integer end - def type_cast_from_database(value) + def deserialize(value) return if value.nil? value.to_i end diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index 6c6c520048..67aac58b1d 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -11,7 +11,7 @@ module ActiveRecord super(subtype) end - def type_cast_from_database(value) + def deserialize(value) if default_value?(value) value else diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb index 7338920f3b..d6b61ead63 100644 --- a/activerecord/lib/active_record/type/value.rb +++ b/activerecord/lib/active_record/type/value.rb @@ -18,7 +18,7 @@ module ActiveRecord # Value#type_cast and Value#cast_value. # # +value+ The raw input, as provided from the database. - def type_cast_from_database(value) + def deserialize(value) type_cast(value) end @@ -73,11 +73,11 @@ module ActiveRecord # # or # - # - pass +raw_old_value+ to Value#type_cast_from_database and compare it to + # - pass +raw_old_value+ to Value#deserialize and compare it to # +new_value+ # # +raw_old_value+ The original value, before being passed to - # +type_cast_from_database+. + # +deserialize+. # # +new_value+ The current value, after type casting. def changed_in_place?(raw_old_value, new_value) @@ -94,7 +94,7 @@ module ActiveRecord private # Convenience method. If you don't need separate behavior for - # Value#type_cast_from_database and Value#type_cast_from_user, you can override + # Value#deserialize and Value#type_cast_from_user, you can override # this method instead. The default behavior of both methods is to call # this one. See also Value#cast_value. def type_cast(value) # :doc: |