lib/dry/behaviour/black_tie.rb in dry-behaviour-0.4.0 vs lib/dry/behaviour/black_tie.rb in dry-behaviour-0.4.1

- old
+ new

@@ -66,23 +66,30 @@ end end end end + POSTPONE_EXTEND = lambda do |target, protocol| + TracePoint.new(:end) do |tp| + if tp.self == protocol + puts "#{tp.self.inspect} | #{protocol.name}" + target.extend protocol + 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) + Module.new do mds.each(&DELEGATE_METHOD.curry[singleton_class]) singleton_class.class_eval(&Proc.new) if block_given? # block takes precedence - if protocol - extend protocol - else # FIXME: - BlackTie.Logger.warn('Cross-calling protocol methods is not yet implemented for inplace declarated implementations.') - end end.tap do |mod| - protocol ||= self + protocol ? mod.extend(protocol) : POSTPONE_EXTEND.(mod, protocol = self) mod.methods(false).tap do |meths| (BlackTie.protocols[protocol].keys - meths).each_with_object(meths) do |m, acc| BlackTie.Logger.warn("Implicit delegate #{protocol.inspect}##{m} to #{target}") DELEGATE_METHOD.(mod.singleton_class, [m] * 2)