Class: Lumberjack::MultiDevice
- Inherits:
-
Device
- Object
- Device
- Lumberjack::MultiDevice
- 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
-
#devices ⇒ Object
Returns the value of attribute devices.
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(devices = []) ⇒ MultiDevice
constructor
A new instance of MultiDevice.
- #method_missing(method, params, &block) ⇒ Object
- #respond_to?(method, include_private = false) ⇒ Boolean
- #write(entry) ⇒ Object
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
#devices ⇒ Object
Returns the value of attribute devices.
8 9 10 |
# File 'lib/lumberjack_multi-device.rb', line 8 def devices @devices end |
Instance Method Details
#close ⇒ Object
39 40 41 42 43 |
# File 'lib/lumberjack_multi-device.rb', line 39 def close @devices.map do |device| device.close end end |
#flush ⇒ Object
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
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 |