Sha256: 436682caf7c20b8c1529429f31c893e5b03f683b685e5bcba081d43da52236d0

Contents?: true

Size: 938 Bytes

Versions: 17

Compression:

Stored size: 938 Bytes

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)
        coercers[value.class].public_send(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

17 entries across 15 versions & 5 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/attribute/coercer.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/attribute/coercer.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/attribute/coercer.rb
virtus2-2.0.1 lib/virtus/attribute/coercer.rb
virtus-2.0.0 lib/virtus/attribute/coercer.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/virtus-1.0.5/lib/virtus/attribute/coercer.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/virtus-1.0.5/lib/virtus/attribute/coercer.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/lib/virtus/attribute/coercer.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/lib/virtus/attribute/coercer.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/lib/virtus/attribute/coercer.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/lib/virtus/attribute/coercer.rb
virtus-1.0.5 lib/virtus/attribute/coercer.rb
virtus-1.0.4 lib/virtus/attribute/coercer.rb
virtus-1.0.3 lib/virtus/attribute/coercer.rb
virtus-1.0.2 lib/virtus/attribute/coercer.rb
virtus-1.0.1 lib/virtus/attribute/coercer.rb
virtus-1.0.0 lib/virtus/attribute/coercer.rb