Exception: Dry::Protocol::NotImplemented

Inherits:
StandardError
  • Object
show all
Defined in:
lib/dry/errors/not_implemented.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, proto, **details) ⇒ NotImplemented

Returns a new instance of NotImplemented.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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.\n" \
      " ⮩  caused by “#{cause.class}” with a message\n" \
      " ⮩    “#{cause.message}”\n" \
      " ⮩  rescue this exception and inspect `NotImplemented#cause' for details."
    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

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



4
5
6
# File 'lib/dry/errors/not_implemented.rb', line 4

def details
  @details
end

#protoObject (readonly)

Returns the value of attribute proto.



4
5
6
# File 'lib/dry/errors/not_implemented.rb', line 4

def proto
  @proto
end

Instance Method Details

#causeObject



35
36
37
# File 'lib/dry/errors/not_implemented.rb', line 35

def cause
  @details[:cause] ||= super
end