lib/virtus/attribute/coercer.rb in virtus-1.0.0.rc2 vs lib/virtus/attribute/coercer.rb in virtus-1.0.0

- old
+ new

@@ -2,48 +2,42 @@ class Attribute # Coercer accessor wrapper # # @api private - class Coercer - attr_reader :method + class Coercer < Virtus::Coercer + # @api private + attr_reader :method, :coercers + # Initialize a new coercer object # # @param [Object] coercers accessor # @param [Symbol] coercion method # # @return [undefined] # # @api private - def initialize(coercers, method) + def initialize(type, coercers) + super(type) + @method = type.coercion_method @coercers = coercers - @method = method end # Coerce given value # # @return [Object] # # @api private def call(value) - self[value.class].public_send(@method, value) + coercers[value.class].public_send(method, value) rescue ::Coercible::UnsupportedCoercion value end # @api public def success?(primitive, value) - self[primitive].coerced?(value) - end - - # Return coercer object for the given type - # - # @return [Object] - # - # @api private - def [](type) - @coercers[type] + coercers[primitive].coerced?(value) end end # class Coercer end # class Attribute