Class: MailToHipChat::ChuteChain

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_to_hip_chat/chute_chain.rb

Overview

A ChuteChain is used to hold a collection of chutes and to check whether any of those chutes is able to handle a message to hand off to HipChat. Anything that responds to #call can be pushed onto the chain.

Instance Method Summary collapse

Constructor Details

#initializeChuteChain

Returns a new instance of ChuteChain.



7
8
9
# File 'lib/mail_to_hip_chat/chute_chain.rb', line 7

def initialize
  @chutes = []
end

Instance Method Details

#accept(message) ⇒ true, false

Takes in a message and traverses the chain looking for a chute that will handle it.

Parameters:

  • message (Hash)

    The message to give to the chutes in the chain.

Returns:

  • (true)

    True if a chute accepts the message.

  • (false)

    False if no chute can accept the message.



27
28
29
# File 'lib/mail_to_hip_chat/chute_chain.rb', line 27

def accept(message)
  @chutes.any? { |chute| chute.call(message) }
end

#push(chute) ⇒ self

Pushes a chute onto the chain.

Parameters:

  • chute (#call)

    The chute to push onto the chain.

Returns:

  • (self)


16
17
18
19
# File 'lib/mail_to_hip_chat/chute_chain.rb', line 16

def push(chute)
  @chutes.push(chute)
  self
end