Sha256: 55d7f2b54b3da4e775ec7bd37736dcc5373673c33d7043537506fdf32e24dafc

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'kind/maybe'

module Kind
  module Object
    include Kind::BasicObject
    include Maybe::Buildable
    include UnionType::Buildable

    def name
      kind.name
    end

    def ===(value)
      kind === value
    end

    def inspect
      "Kind::Object<#{name}>"
    end
  end

  class Object::Instance # :nodoc: all
    include ::Kind::Object

    ResolveKindName = ->(kind, opt) do
      name = Try.call!(opt, :[], :name)
      name || Try.call!(kind, :name)
    end

    attr_reader :kind, :name

    def initialize(kind, opt)
      name = ResolveKindName.(kind, opt)

      @name = KIND.of!(::String, name)
      @kind = KIND.respond_to!(:===, kind)
    end

    private_constant :ResolveKindName
  end

  # Kind[]
  def self.[](kind, opt = Empty::HASH)
    Object::Instance.new(kind, opt)
  end

  # Kind::Of()
  def self.Of(*args)
    warn '[DEPRECATION] Kind::Of() is deprecated; use Kind[] instead. ' \
        'It will be removed on next major release.'

    self[*args]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kind-5.2.0 lib/kind/objects/object.rb