Sha256: 4c81007d966ebedbdbe8c08100461f03ed66c36f8bf73b8ea42c396638e8b5f5

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 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 = STRICT.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

8 entries across 8 versions & 1 rubygems

Version Path
kind-5.8.1 lib/kind/objects/object.rb
kind-5.8.0 lib/kind/objects/object.rb
kind-5.7.0 lib/kind/objects/object.rb
kind-5.6.0 lib/kind/objects/object.rb
kind-5.5.0 lib/kind/objects/object.rb
kind-5.4.1 lib/kind/objects/object.rb
kind-5.4.0 lib/kind/objects/object.rb
kind-5.3.0 lib/kind/objects/object.rb