Sha256: 466ea8411951afb74528b6de71aa829ed90f404da7dabc45c58f8baec23f3b40

Contents?: true

Size: 805 Bytes

Versions: 7

Compression:

Stored size: 805 Bytes

Contents

module Virtus

  # Abstract coercer class
  #
  class Coercer
    include Equalizer.new(inspect) << :primitive << :type

    # @api private
    attr_reader :primitive, :type

    # @api private
    def initialize(type)
      @type      = type
      @primitive = type.primitive
    end

    # Coerce input value into expected primitive type
    #
    # @param [Object] input
    #
    # @return [Object] coerced input
    #
    # @api public
    def call(input)
      NotImplementedError.new("#{self.class}#call must be implemented")
    end

    # Return if the input value was successfuly coerced
    #
    # @param [Object] input
    #
    # @return [Object] coerced input
    #
    # @api public
    def success?(primitive, input)
      input.kind_of?(primitive)
    end

  end # Coercer

end # Virtus

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/coercer.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/coercer.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/coercer.rb
virtus2-2.1.0 lib/virtus/coercer.rb
virtus2-2.0.2 lib/virtus/coercer.rb
virtus2-2.0.1 lib/virtus/coercer.rb
virtus-2.0.0 lib/virtus/coercer.rb