diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-02-17 13:39:42 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-02-17 13:39:42 -0700 |
commit | 9ca6948f72bef56445030a60e346376a821dbc72 (patch) | |
tree | 669b2e9b835a09067079c2afb3ff86df00e912e1 /activerecord/lib | |
parent | 1455c4c22feb24b0ff2cbb191afb0bd98ebf7b06 (diff) | |
download | rails-9ca6948f72bef56445030a60e346376a821dbc72.tar.gz rails-9ca6948f72bef56445030a60e346376a821dbc72.tar.bz2 rails-9ca6948f72bef56445030a60e346376a821dbc72.zip |
`type_cast_from_user` -> `cast`
Diffstat (limited to 'activerecord/lib')
10 files changed, 16 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 33e4516bd1..eea847cfa3 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -63,7 +63,7 @@ module ActiveRecord def ids_writer(ids) pk_type = reflection.primary_key_type ids = Array(ids).reject(&:blank?) - ids.map! { |i| pk_type.type_cast_from_user(i) } + ids.map! { |i| pk_type.cast(i) } replace(klass.find(ids).index_by(&:id).values_at(*ids)) end diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb index 0be0fc79f5..73dd3fa041 100644 --- a/activerecord/lib/active_record/attribute.rb +++ b/activerecord/lib/active_record/attribute.rb @@ -114,7 +114,7 @@ module ActiveRecord class FromUser < Attribute # :nodoc: def type_cast(value) - type.type_cast_from_user(value) + type.cast(value) end def came_from_user? 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 f6a9fff343..f9beb43e4b 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -6,9 +6,9 @@ module ActiveRecord convert_time_to_time_zone(super) end - def type_cast_from_user(value) + def cast(value) if value.is_a?(Array) - value.map { |v| type_cast_from_user(v) } + value.map { |v| cast(v) } elsif value.is_a?(Hash) set_time_zone_without_conversion(super) elsif value.respond_to?(:in_time_zone) diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index 650712dd19..45a764bd5a 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -102,14 +102,14 @@ 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 - # +deserialize+ or +type_cast_from_user+ will be called on + # +deserialize+ or +cast+ 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 # from ActiveRecord::Type::Value # # class MoneyType < ActiveRecord::Type::Integer - # def type_cast_from_user(value) + # def cast(value) # if value.include?('$') # price_in_dollars = value.gsub(/\$/, '').to_f # super(price_in_dollars * 100) @@ -144,7 +144,7 @@ module ActiveRecord # end # # # value will be the result of +deserialize+ or - # # +type_cast_from_user+. Assumed to be in instance of +Money+ in + # # +cast+. Assumed to be in instance of +Money+ in # # this case. # def serialize(value) # value_in_bitcoins = @currency_converter.convert_to_bitcoins(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 +deserialize+. + # +cast+ or +deserialize+. def define_attribute( name, cast_type, 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 ca9ceff5e4..fb4e0de2a8 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb @@ -33,11 +33,11 @@ module ActiveRecord end end - def type_cast_from_user(value) + def cast(value) if value.is_a?(::String) value = parse_pg_array(value) end - type_cast_array(value, :type_cast_from_user) + type_cast_array(value, :cast) end def serialize(value) diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 9a5db58e78..ea88983917 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -93,7 +93,7 @@ module ActiveRecord @mapping = mapping end - def type_cast_from_user(value) + def cast(value) return if value.blank? if mapping.has_key?(value) diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 117a128579..084ef397a8 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -521,7 +521,7 @@ module ActiveRecord # Determines if a hash contains a truthy _destroy key. def has_destroy_flag?(hash) - Type::Boolean.new.type_cast_from_user(hash['_destroy']) + Type::Boolean.new.cast(hash['_destroy']) end # Determines if a new record should be rejected by checking diff --git a/activerecord/lib/active_record/type/helpers/accepts_multiparameter_time.rb b/activerecord/lib/active_record/type/helpers/accepts_multiparameter_time.rb index 640943c5e9..be571fc1c7 100644 --- a/activerecord/lib/active_record/type/helpers/accepts_multiparameter_time.rb +++ b/activerecord/lib/active_record/type/helpers/accepts_multiparameter_time.rb @@ -3,7 +3,7 @@ module ActiveRecord module Helpers class AcceptsMultiparameterTime < Module # :nodoc: def initialize(defaults: {}) - define_method(:type_cast_from_user) do |value| + define_method(:cast) do |value| if value.is_a?(Hash) value_from_multiparameter_assignment(value) else diff --git a/activerecord/lib/active_record/type/helpers/mutable.rb b/activerecord/lib/active_record/type/helpers/mutable.rb index 94f246f567..88a9099277 100644 --- a/activerecord/lib/active_record/type/helpers/mutable.rb +++ b/activerecord/lib/active_record/type/helpers/mutable.rb @@ -2,7 +2,7 @@ module ActiveRecord module Type module Helpers module Mutable # :nodoc: - def type_cast_from_user(value) + def cast(value) deserialize(serialize(value)) end diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb index 021685c4c4..cdac1f9fa9 100644 --- a/activerecord/lib/active_record/type/value.rb +++ b/activerecord/lib/active_record/type/value.rb @@ -32,7 +32,7 @@ module ActiveRecord # Value#type_cast and Value#cast_value. # # +value+ The raw input, as provided to the attribute setter. - def type_cast_from_user(value) + def cast(value) type_cast(value) end @@ -94,7 +94,7 @@ module ActiveRecord private # Convenience method. If you don't need separate behavior for - # Value#deserialize and Value#type_cast_from_user, you can override + # Value#deserialize and Value#cast, 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: |