Sha256: dc4227b55b386eb417c3a57240988d58068b4810e79d2d224eed5a3d926c4e6e

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# typed: strict

module Mocktail
  class Call < T::Struct
    extend T::Sig

    const :singleton, T.nilable(T::Boolean)
    const :double, Object, default: nil
    const :original_type, T.nilable(T.any(T::Class[T.anything], Module))
    const :dry_type, T.nilable(T.any(T::Class[T.anything], Module))
    const :method, T.nilable(Symbol), without_accessors: true
    const :original_method, T.nilable(T.any(UnboundMethod, Method))
    const :args, T::Array[T.untyped], default: []
    const :kwargs, T::Hash[Symbol, T.untyped], default: {}
    # At present, there's no way to type optional/variadic params in blocks
    #   (i.e. `T.proc.params(*T.untyped).returns(T.untyped)` doesn't work)
    #
    # See: https://github.com/sorbet/sorbet/issues/1142#issuecomment-1586195730
    const :block, T.nilable(Proc)

    sig { returns(T.nilable(Symbol)) }
    attr_reader :method

    # Because T::Struct compares with referential equality, we need
    # to redefine the equality methods to compare the values of the attributes.
    sig { params(other: T.nilable(T.anything)).returns(T::Boolean) }
    def ==(other)
      eql?(other)
    end

    sig { params(other: T.anything).returns(T::Boolean) }
    def eql?(other)
      case other
      when Call
        [
          :singleton, :double, :original_type, :dry_type,
          :method, :original_method, :args, :kwargs, :block
        ].all? { |attr|
          instance_variable_get("@#{attr}") == other.send(attr)
        }
      else
        false
      end
    end

    sig { returns(Integer) }
    def hash
      [@singleton, @double, @original_type, @dry_type, @method, @original_method, @args, @kwargs, @block].hash
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocktail-2.0.0 lib/mocktail/sorbet/mocktail/value/call.rb