Class: Slnky::Service::Subscriber
- Inherits:
-
Object
- Object
- Slnky::Service::Subscriber
- Defined in:
- lib/slnky/service/subscriber.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(name, method) ⇒ Object
- #each ⇒ Object
- #for(name) ⇒ Object
- #handle(name, data) ⇒ Object
-
#initialize ⇒ Subscriber
constructor
A new instance of Subscriber.
- #list ⇒ Object
Constructor Details
#initialize ⇒ Subscriber
Returns a new instance of Subscriber.
16 17 18 |
# File 'lib/slnky/service/subscriber.rb', line 16 def initialize @subscriptions = [] end |
Class Method Details
.instance ⇒ Object
11 12 13 |
# File 'lib/slnky/service/subscriber.rb', line 11 def instance @instance ||= self.new end |
Instance Method Details
#add(name, method) ⇒ Object
24 25 26 |
# File 'lib/slnky/service/subscriber.rb', line 24 def add(name, method) @subscriptions << Slnky::Service::Subscription.new(name, method) end |
#each ⇒ Object
32 33 34 35 36 |
# File 'lib/slnky/service/subscriber.rb', line 32 def each @subscriptions.each do |sub| yield sub.name, sub.method end end |
#for(name) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/slnky/service/subscriber.rb', line 38 def for(name) @subscriptions.each do |sub| if sub.name == name || File.fnmatch(sub.name, name) yield sub.name, sub.method if block_given? end end end |
#handle(name, data) ⇒ Object
20 21 22 |
# File 'lib/slnky/service/subscriber.rb', line 20 def handle(name, data) end |
#list ⇒ Object
28 29 30 |
# File 'lib/slnky/service/subscriber.rb', line 28 def list @subscriptions end |