Class: Lumberjack::MultiDevice

Inherits:
Device
  • Object
show all
Defined in:
lib/lumberjack_multi-device.rb

Overview

Write Lumberjack log entries to multiple devices.

Calls to this device will be repeated to all devices assigned.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(devices = []) ⇒ MultiDevice

Returns a new instance of MultiDevice.



10
11
12
13
# File 'lib/lumberjack_multi-device.rb', line 10

def initialize(devices = [])
  devices = [devices] unless devices.is_a?(Array)
  @devices = devices
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, params, &block) ⇒ Object



21
22
23
24
25
# File 'lib/lumberjack_multi-device.rb', line 21

def method_missing(method, params, &block)
  @devices.each do |device|
    device.send(method, *params, &block)
  end
end

Instance Attribute Details

#devicesObject

Returns the value of attribute devices.



8
9
10
# File 'lib/lumberjack_multi-device.rb', line 8

def devices
  @devices
end

Instance Method Details

#closeObject



39
40
41
42
43
# File 'lib/lumberjack_multi-device.rb', line 39

def close
  @devices.map do |device|
    device.close
  end
end

#flushObject



33
34
35
36
37
# File 'lib/lumberjack_multi-device.rb', line 33

def flush
  @devices.map do |device|
    device.flush
  end
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/lumberjack_multi-device.rb', line 15

def respond_to?(method, include_private = false)
  @devices.all? do |device|
    device.respond_to?(method, include_private)
  end || super
end

#write(entry) ⇒ Object



27
28
29
30
31
# File 'lib/lumberjack_multi-device.rb', line 27

def write(entry)
  @devices.map do |device|
    device.write(entry)
  end
end