Class: Karafka::Helpers::MultiDelegator

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/helpers/multi_delegator.rb

Overview

Multidelegator is used to delegate calls to multiple targets.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*targets) ⇒ MultiDelegator

Returns a new instance of MultiDelegator.

Parameters:

  • targets

    to which we want to delegate methods



10
11
12
# File 'lib/karafka/helpers/multi_delegator.rb', line 10

def initialize(*targets)
  @targets = targets
end

Class Method Details

.delegate(*methods) ⇒ Object

Examples:

Delegate write and close to STDOUT and file

Logger.new MultiDelegator.delegate(:write, :close).to(STDOUT, log_file)

Parameters:

  • methods

    names that should be delegated to



18
19
20
21
22
23
24
25
26
# File 'lib/karafka/helpers/multi_delegator.rb', line 18

def delegate(*methods)
  methods.each do |m|
    define_method(m) do |*args|
      @targets.map { |t| t.send(m, *args) }
    end
  end

  self
end