Sha256: 3037c9c7f3d9b2719002d57858ba8f895739d0c08aa6a1261603fc6c6a987923

Contents?: true

Size: 1018 Bytes

Versions: 5

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

require 'kind/__lib__/of'

module Kind
  module STRICT
    extend self

    def error(kind_name, value, label = nil) # :nodoc:
      raise Error.new(kind_name, value, label: label)
    end

    def object_is_a(kind, value, label = nil) # :nodoc:
      return value if kind === value

      error(kind.name, value, label)
    end

    def kind_of(kind, value, kind_name = nil) # :nodoc:
      return value if kind === value

      error(kind_name || kind.name, value)
    end

    def module_or_class(value) # :nodoc:
      kind_of(::Module, value, 'Module/Class')
    end

    def class!(value) # :nodoc:
      kind_of(::Class, value)
    end

    def module!(value) # :nodoc:
      return value if OF.module?(value)

      error('Module', value)
    end

    def not_nil(value, label) # :nodoc:
      return value unless value.nil?

      label_text = label ? "#{label}: " : ''

      raise Error.new("#{label_text}expected to not be nil")
    end
  end

  private_constant :STRICT
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kind-5.6.0 lib/kind/__lib__/strict.rb
kind-5.5.0 lib/kind/__lib__/strict.rb
kind-5.4.1 lib/kind/__lib__/strict.rb
kind-5.4.0 lib/kind/__lib__/strict.rb
kind-5.3.0 lib/kind/__lib__/strict.rb