diff --git a/lib/active_attr/typecasting.rb b/lib/active_attr/typecasting.rb index 9c09f44..bf29031 100644 --- a/lib/active_attr/typecasting.rb +++ b/lib/active_attr/typecasting.rb @@ -26,14 +26,14 @@ module ActiveAttr module Typecasting # @private TYPECASTER_MAP = { - BigDecimal => BigDecimalTypecaster, - Boolean => BooleanTypecaster, - Date => DateTypecaster, - DateTime => DateTimeTypecaster, - Float => FloatTypecaster, - Integer => IntegerTypecaster, - Object => ObjectTypecaster, - String => StringTypecaster, + BigDecimal => BigDecimalTypecaster.new, + Boolean => BooleanTypecaster.new, + Date => DateTypecaster.new, + DateTime => DateTimeTypecaster.new, + Float => FloatTypecaster.new, + Integer => IntegerTypecaster.new, + Object => ObjectTypecaster.new, + String => StringTypecaster.new, }.freeze # Typecasts a value using a Class @@ -51,16 +51,16 @@ def typecast_attribute(typecaster, value) typecaster.call(value) end - # Resolve a Class to a typecaster + # Resolve an Instance to a typecaster # # @param [Class] type The type to cast to # - # @return [#call, nil] The typecaster to use + # @return [#call, nil] The typecaster instance to use # # @since 0.6.0 def typecaster_for(type) typecaster = TYPECASTER_MAP[type] - typecaster.new if typecaster + typecaster if typecaster end end end