lib/dry/behaviour.rb in dry-behaviour-0.4.2 vs lib/dry/behaviour.rb in dry-behaviour-0.5.0
- old
+ new
@@ -1,25 +1,47 @@
require 'dry/behaviour/version'
-require 'dry/errors/not_implemented'
-require 'dry/errors/not_protocol'
+require 'dry/errors'
require 'dry/behaviour/black_tie'
+require 'dry/behaviour/cerberus'
module Dry
+ # rubocop:disable Style/AsciiIdentifiers
+ # rubocop:disable Style/EmptyCaseCondition
+ DEFINE_METHOD = lambda do |target, this, *args, **params, &λ|
+ case
+ when !args.empty? && !params.empty? then this.send(target, *args, **params, &λ)
+ when !args.empty? then this.send(target, *args, &λ)
+ when !params.empty? then this.send(target, **params, &λ)
+ else this.send(target, &λ)
+ end
+ end
+ # rubocop:enable Style/EmptyCaseCondition
+ # rubocop:enable Style/AsciiIdentifiers
+
module Protocol
def self.included(base)
- base.singleton_class.prepend(Dry::BlackTie)
+ base.singleton_class.prepend(::Dry::BlackTie)
end
class << self
# 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
+ # rubocop:disable Style/RaiseArgs
def implemented_for?(protocol, receiver)
- raise NotProtocol.new(protocol) unless protocol < ::Dry::Protocol
+ raise ::Dry::Protocol::NotProtocol.new(protocol) unless protocol < ::Dry::Protocol
!protocol.implementation_for(receiver).nil?
end
+ # rubocop:enable Style/RaiseArgs
+ end
+ end
+
+ module Guards
+ def self.included(base)
+ ::Dry::Cerberus::POSTPONE_FIX_CLAUSES.(base)
+ base.singleton_class.prepend(::Dry::Cerberus)
end
end
end