Class: Vissen::Input::Subscription

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vissen/input/subscription.rb

Overview

Whenever a callable object wants to receive messages from a broker it is wrapped inside of a subscription. A subscription is a basic immutable value object with a minimal api that keeps track of three things: a Matcher, a callable handler and a numeric priority.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, handler, priority) ⇒ Subscription

Returns a new instance of Subscription.

Parameters:

  • matcher (#match?)

    the matcher to use when filtering messages.

  • handler (#call)

    the target of the subscription.

  • priority (Integer)

    the priority of the subscription relative other subscriptions.



36
37
38
39
40
41
42
# File 'lib/vissen/input/subscription.rb', line 36

def initialize(matcher, handler, priority)
  @matcher  = matcher
  @handler  = handler
  @priority = priority

  freeze
end

Instance Attribute Details

#priorityInteger (readonly)

Returns the subscription priority.

Returns:

  • (Integer)

    the subscription priority.



15
16
17
# File 'lib/vissen/input/subscription.rb', line 15

def priority
  @priority
end

Instance Method Details

#handle(message) ⇒ Object

Calls the registered handler with the given message.

Parameters:

  • message (Message)

    the message that the subscriber should handle.



30
# File 'lib/vissen/input/subscription.rb', line 30

def_delegator :@handler, :call, :handle

#match?(message) ⇒ true, false

This method is forwarded to Matcher#match?.

Returns:

  • (true, false)

    (see Matcher#match?).



22
# File 'lib/vissen/input/subscription.rb', line 22

def_delegator :@matcher, :match?, :match?