Sha256: 8bff92ca2c26fa8a03018a01eb929b2e942d4e4a31cabd2a58ae5e86ad5ed42e
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
module Virtus class Attribute # Coercer accessor wrapper # # @api private 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(type, coercers) super(type) @method = type.coercion_method @coercers = coercers end # Coerce given value # # @return [Object] # # @api private def call(value) call_method = (method == :to_hash && value.kind_of?(Hash)) ? :itself : method coercers[value.class].public_send(call_method, value) rescue ::Coercible::UnsupportedCoercion value end # @api public def success?(primitive, value) coercers[primitive].coerced?(value) end end # class Coercer end # class Attribute end # module Virtus
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
virtus2-2.1.0 | lib/virtus/attribute/coercer.rb |
virtus2-2.0.2 | lib/virtus/attribute/coercer.rb |