Class: Tavern::MockHub
Overview
A simple hub you can use to completely disable the pub / sub process but still record what happens.
Defined Under Namespace
Classes: Publication
Instance Attribute Summary collapse
-
#publications ⇒ Object
readonly
Returns the value of attribute publications.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#unsubscriptions ⇒ Object
readonly
Returns the value of attribute unsubscriptions.
Instance Method Summary collapse
-
#initialize ⇒ MockHub
constructor
A new instance of MockHub.
-
#publish(path, context = {}) ⇒ Object
Publishes a message to the given path and with a given hash context.
-
#subscribe(path, object = nil, &blk) ⇒ Object
Subscribes to a given path string and either a proc callback or any object responding to #call.
-
#unsubscribe(subscription) ⇒ Subscription
Deletes the given subscription from this pub sub hub.
Methods inherited from Hub
Constructor Details
#initialize ⇒ MockHub
Returns a new instance of MockHub.
13 14 15 16 |
# File 'lib/tavern/mock_hub.rb', line 13 def initialize super @subscriptions, @unsubscriptions, @publications = [], [], [] end |
Instance Attribute Details
#publications ⇒ Object (readonly)
Returns the value of attribute publications.
11 12 13 |
# File 'lib/tavern/mock_hub.rb', line 11 def publications @publications end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
11 12 13 |
# File 'lib/tavern/mock_hub.rb', line 11 def subscriptions @subscriptions end |
#unsubscriptions ⇒ Object (readonly)
Returns the value of attribute unsubscriptions.
11 12 13 |
# File 'lib/tavern/mock_hub.rb', line 11 def unsubscriptions @unsubscriptions end |
Instance Method Details
#publish(path, context = {}) ⇒ Object
Publishes a message to the given path and with a given hash context.
49 50 51 |
# File 'lib/tavern/mock_hub.rb', line 49 def publish(path, context = {}) publications << Publication.new(path, context) end |
#subscribe(path, object = nil, &blk) ⇒ Object
Subscribes to a given path string and either a proc callback or any object responding to #call.
29 30 31 32 33 |
# File 'lib/tavern/mock_hub.rb', line 29 def subscribe(path, object = nil, &blk) subscription = Subscription.new(path, (object || blk)) subscriptions << subscription subscription end |
#unsubscribe(subscription) ⇒ Subscription
Deletes the given subscription from this pub sub hub.
38 39 40 41 42 |
# File 'lib/tavern/mock_hub.rb', line 38 def unsubscribe(subscription) return if subscription.blank? subscriptions.delete subscription subscription end |