Sha256: f77dc841f52c4a518461e47a727560b8f525a9a72796a318c5f5177cf191f771

Contents?: true

Size: 932 Bytes

Versions: 28

Compression:

Stored size: 932 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

28 entries across 28 versions & 1 rubygems

Version Path
karafka-1.2.13 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.12 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.11 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.10 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.9 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.8 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.7 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.6 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.5 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.4 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.3 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.2 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.1 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.0 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.0.beta4 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.0.beta3 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.0.beta2 lib/karafka/helpers/multi_delegator.rb
karafka-1.2.0.beta1 lib/karafka/helpers/multi_delegator.rb
karafka-1.1.2 lib/karafka/helpers/multi_delegator.rb
karafka-1.1.1 lib/karafka/helpers/multi_delegator.rb