Class: Tavern::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/tavern/subscription.rb

Overview

A general subscription in a given hub, including a name and a given callback block. As part of this, it provides tools to make it easy to handle the subscriptions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, callback) ⇒ Subscription

Initializes a new subscription with a given name and callback.

Parameters:

  • name (String)

    the name of this subscription

  • callback (#call)

    the callback for this subscription



11
12
13
14
15
# File 'lib/tavern/subscription.rb', line 11

def initialize(name, callback)
  @name            = name.to_s
  @callback        = callback
  @_subscribe_keys = @name.to_s.split(":")
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



6
7
8
# File 'lib/tavern/subscription.rb', line 6

def callback
  @callback
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/tavern/subscription.rb', line 6

def name
  @name
end

Instance Method Details

#call(context) ⇒ Object

Invokes the callback, returning whatever it returns.

Parameters:

  • context (Hash)

    the callback context.



25
26
27
# File 'lib/tavern/subscription.rb', line 25

def call(context)
  @callback.call context
end

#to_procObject



29
30
31
# File 'lib/tavern/subscription.rb', line 29

def to_proc
  proc { |ctx| call ctx }
end

#to_subscribe_keysArray<String>

Returns the list of subscription sublevel keys.

Returns:

  • (Array<String>)

    the list of sublevel keys



19
20
21
# File 'lib/tavern/subscription.rb', line 19

def to_subscribe_keys
  @_subscribe_keys
end