Class: Warren::Handler::Log

Inherits:
Base
  • Object
show all
Defined in:
lib/warren/handler/log.rb

Overview

Class Warren::Log provides a dummy RabbitMQ connection pool for use during development

Defined Under Namespace

Classes: Channel, Exchange, Queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#connect, #disconnect

Constructor Details

#initialize(logger:, routing_key_prefix: nil) ⇒ Log

Returns a new instance of Log.



73
74
75
76
77
# File 'lib/warren/handler/log.rb', line 73

def initialize(logger:, routing_key_prefix: nil)
  super()
  @logger = logger
  @routing_key_template = Handler.routing_key_template(routing_key_prefix)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



71
72
73
# File 'lib/warren/handler/log.rb', line 71

def logger
  @logger
end

Instance Method Details

#<<(message) ⇒ Warren::Log

Sends a message to the log channel. Useful if you only need to send one message.

Parameters:

  • message (Warren::Message)

    The message to broadcast. Must respond to #routing_key and #payload

Returns:

  • (Warren::Log)

    Returns itself to allow chaining. But you’re probably better off using #with_channel in that case



104
105
106
# File 'lib/warren/handler/log.rb', line 104

def <<(message)
  with_channel { |c| c << message }
end

#new_channelObject



79
80
81
# File 'lib/warren/handler/log.rb', line 79

def new_channel
  Channel.new(@logger, routing_key_template: @routing_key_template)
end

#with_channel {|new_channel| ... } ⇒ void

This method returns an undefined value.

Yields a Warren::Log::Channel

Yields:

Yield Returns:

  • (Warren::Log::Channel)

    A rabbitMQ channel that logs messaged to the test warren



90
91
92
# File 'lib/warren/handler/log.rb', line 90

def with_channel
  yield new_channel
end