lib/dry/behaviour/black_tie.rb in dry-behaviour-0.4.2 vs lib/dry/behaviour/black_tie.rb in dry-behaviour-0.5.0

- old
+ new

@@ -1,10 +1,8 @@ module Dry - # rubocop:disable Style/AsciiIdentifiers # rubocop:disable Style/MultilineBlockChain - # rubocop:disable Style/EmptyCaseCondition - # rubocop:disable Metrics/PerceivedComplexity + # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/AbcSize # rubocop:disable Style/MethodName module BlackTie class << self @@ -36,11 +34,10 @@ end BlackTie.protocols[self].each do |method, *_| # FIXME: CHECK PARAMS CORRESPONDENCE HERE singleton_class.send :define_method, method do |receiver = nil, *args| impl = implementation_for(receiver) - raise Dry::Protocol::NotImplemented.new(:protocol, inspect, receiver.class) unless impl begin impl[method].(*args.unshift(receiver)) rescue NoMethodError => e raise Dry::Protocol::NotImplemented.new(:method, inspect, e.message) @@ -55,18 +52,11 @@ BlackTie.protocols[self][name] = params end DELEGATE_METHOD = lambda do |klazz, (source, target)| klazz.class_eval do - define_method source do |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 + define_method(source, &Dry::DEFINE_METHOD.curry[target]) end end POSTPONE_EXTEND = lambda do |target, protocol| TracePoint.new(:end) do |tp| @@ -75,11 +65,10 @@ tp.disable end end.enable end - def defimpl(protocol = nil, target: nil, delegate: [], map: {}) raise if target.nil? || !block_given? && delegate.empty? && map.empty? mds = normalize_map_delegates(delegate, map) @@ -126,10 +115,8 @@ module_function :normalize_map_delegates end # rubocop:enable Style/MethodName # rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/CyclomaticComplexity - # rubocop:enable Metrics/PerceivedComplexity - # rubocop:enable Style/EmptyCaseCondition + # rubocop:enable Metrics/MethodLength # rubocop:enable Style/MultilineBlockChain - # rubocop:enable Style/AsciiIdentifiers end