lib/dry/behaviour.rb in dry-behaviour-0.3.0 vs lib/dry/behaviour.rb in dry-behaviour-0.3.1

- old
+ new

@@ -1,7 +1,8 @@ require 'dry/behaviour/version' require 'dry/errors/not_implemented' +require 'dry/errors/not_protocol' require 'dry/behaviour/black_tie' module Dry module Protocol def self.included(base) @@ -12,8 +13,13 @@ # rubocop:disable Style/AsciiIdentifiers def defimpl(protocol = nil, target: nil, delegate: [], map: {}, &λ) Dry::BlackTie.defimpl(protocol, target: target, delegate: delegate, map: map, &λ) end # rubocop:enable Style/AsciiIdentifiers + + def implemented_for?(protocol, receiver) + raise NotProtocol.new(protocol) unless protocol < ::Dry::Protocol + !protocol.implementation_for(receiver).nil? + end end end end