Sha256: 802e3f2e521937efa5cd449a3e5aeaa637126874e6293265d7eb4b7abce300ab

Contents?: true

Size: 924 Bytes

Versions: 27

Compression:

Stored size: 924 Bytes

Contents

# frozen_string_literal: true

module Karafka
  # Module containing classes and methods that provide some additional functionalities
  module Helpers
    # @note Taken from http://stackoverflow.com/questions/6407141
    # Multidelegator is used to delegate calls to multiple targets
    class MultiDelegator
      # @param targets to which we want to delegate methods
      def initialize(*targets)
        @targets = targets
      end

      class << self
        # @param methods names that should be delegated to
        # @example Delegate write and close to STDOUT and file
        #   Logger.new MultiDelegator.delegate(:write, :close).to(STDOUT, log_file)
        def delegate(*methods)
          methods.each do |m|
            define_method(m) do |*args|
              @targets.map { |t| t.send(m, *args) }
            end
          end

          self
        end

        alias to new
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
karafka-1.4.15 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.14 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.13 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.12 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.11 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.10 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.9 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.8 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.7 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.6 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.5 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.4 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.3 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.2 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.1 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.0 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.0.rc2 lib/karafka/helpers/multi_delegator.rb
karafka-1.4.0.rc1 lib/karafka/helpers/multi_delegator.rb
karafka-1.3.7 lib/karafka/helpers/multi_delegator.rb
karafka-1.3.6 lib/karafka/helpers/multi_delegator.rb