Class: Tavern::Subscription
- Inherits:
-
Object
- Object
- Tavern::Subscription
- 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
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#call(context) ⇒ Object
Invokes the callback, returning whatever it returns.
-
#initialize(name, callback) ⇒ Subscription
constructor
Initializes a new subscription with a given name and callback.
- #to_proc ⇒ Object
-
#to_subscribe_keys ⇒ Array<String>
Returns the list of subscription sublevel keys.
Constructor Details
#initialize(name, callback) ⇒ Subscription
Initializes a new subscription with a given name and callback.
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
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
6 7 8 |
# File 'lib/tavern/subscription.rb', line 6 def callback @callback end |
#name ⇒ Object (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.
25 26 27 |
# File 'lib/tavern/subscription.rb', line 25 def call(context) @callback.call context end |
#to_proc ⇒ Object
29 30 31 |
# File 'lib/tavern/subscription.rb', line 29 def to_proc proc { |ctx| call ctx } end |
#to_subscribe_keys ⇒ Array<String>
Returns the list of subscription sublevel keys.
19 20 21 |
# File 'lib/tavern/subscription.rb', line 19 def to_subscribe_keys @_subscribe_keys end |