class Dry::Protocol::NotImplemented

Attributes

details[R]
proto[R]

Public Class Methods

new(type, proto, **details) click to toggle source
Calls superclass method
# File lib/dry/errors/not_implemented.rb, line 6
def initialize(type, proto, **details)
  @proto, @details = proto, details

  @details[:message] =
    case type
    when :protocol
      "Protocol “#{@proto}” is not implemented for “#{@details[:receiver].class}”."
    when :method
      "Protocol “#{@proto}” does not declare method “#{@details[:method]}”."
    when :nested
      "Protocol “#{@proto}” failed to invoke the implementation for\n" \
      " ⮩    “#{@details[:receiver].class}##{@details[:method]}”.\n" \
      " ⮩  Caused by “#{cause.class}” with a message\n" \
      " ⮩    “#{cause.message}”\n" \
      " ⮩  Rescue this exception and inspect `NotImplemented#cause' for details."
    when :arity
      "Attempt to implement “#{@proto}#@details[:method]}”\n" \
      " ⮩    with a wrong arity for “#{@details[:target]}”.\n" \
      " ⮩  Expected parameters types:\n" \
      " ⮩    “#{@details[:expected]}”\n" \
      " ⮩  Provided parameters types:\n" \
      " ⮩    “#{@details[:provided]}”\n" \
      " ⮩  Please consider providing a proper implementation."
    else
      "Protocol “#{proto}” is invalid."
    end

  super(@details[:message])

  if @details[:cause]
    set_backtrace(
      @details[:cause].backtrace.reject do |line| # FIXME drop_while ??
        line =~ %r[dry-behaviour/lib/dry/behaviour]
      end
    )
  end
end

Public Instance Methods

cause() click to toggle source
Calls superclass method
# File lib/dry/errors/not_implemented.rb, line 44
def cause
  @details[:cause] ||= super
end