Sha256: cfbe7b2655666b22eba0f1faed1b1bed36452f80322abe93d8f28d4556df0639

Contents?: true

Size: 473 Bytes

Versions: 2

Compression:

Stored size: 473 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Mixture
  module Coerce
    # A class coercion.
    class Class < Base
      type Types::Class

      coerce_to(Types::Object, Itself)
      coerce_to(Types::Class) do |value, type|
        member = type.options.fetch(:members).first
        unless value.is_a?(member)
          fail CoercionError, "Cannot coerce #{value.class} =>" \
               " #{member}"
        end
        value
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mixture-0.7.1 lib/mixture/coerce/class.rb
mixture-0.7.0 lib/mixture/coerce/class.rb