Class: JobManager::TeeStream

Inherits:
Object
  • Object
show all
Defined in:
lib/jobmanager/teestream.rb

Overview

This class represents a stream whose only purpose is to forward messages on to a list of configured streams.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(streams) ⇒ TeeStream

Description:

This method creates an TeeStream instance initialized with the hash of streams passed in. When a message is written to this stream, it will be forwarded to all hash values passed in.

Parameters:

streams

A hash table of stream name to stream.



22
23
24
# File 'lib/jobmanager/teestream.rb', line 22

def initialize(streams)
  @streams = streams
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jobmanager/teestream.rb', line 39

def method_missing(*args, &block)
  is_exception_saved = false
  saved_name = nil
  
  saved_e = nil
  @streams.each do |name, stream|
    begin
      stream.send(*args)
    rescue => saved_e
      is_exception_saved = true
      saved_name = name
    end
  end
  
  if (is_exception_saved)
    @streams.delete(saved_name)
    raise "Caught exception on stream #{saved_name}, Error (#{saved_e.class}): #{saved_e.message}"
  end
end

Instance Attribute Details

#streamsObject (readonly)

Returns the value of attribute streams.



11
12
13
# File 'lib/jobmanager/teestream.rb', line 11

def streams
  @streams
end

Instance Method Details

#stream(name) ⇒ Object

Description:

This method returns the stream associated with the stream name specified.

Parameters:

name

The name of the stream requested.

Returns:

The associated stream if it exists, nil otherwise



35
36
37
# File 'lib/jobmanager/teestream.rb', line 35

def stream(name)
  @streams[name]
end