Sha256: f0e412546008540281b414c9d95ddf14bee937ab12163e0b2c5d4f981fd88901

Contents?: true

Size: 714 Bytes

Versions: 5

Compression:

Stored size: 714 Bytes

Contents

# frozen_string_literal: true

module Strict
  class MethodReturnError < Error
    attr_reader :verifiable_method, :value

    def initialize(verifiable_method:, value:)
      super(message_from(verifiable_method: verifiable_method, value: value))

      @verifiable_method = verifiable_method
      @value = value
    end

    private

    def message_from(verifiable_method:, value:)
      details = invalid_returns_message_from(verifiable_method, value)
      "#{verifiable_method}'s return value was invalid because:\n#{details}"
    end

    def invalid_returns_message_from(verifiable_method, value)
      "  - got #{value.inspect}, expected #{verifiable_method.returns.validator.inspect}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
strict-1.5.0 lib/strict/method_return_error.rb
strict-1.4.0 lib/strict/method_return_error.rb
strict-1.3.1 lib/strict/method_return_error.rb
strict-1.3.0 lib/strict/method_return_error.rb
strict-1.2.0 lib/strict/method_return_error.rb