Class: Rumor::Channel
- Inherits:
-
Object
- Object
- Rumor::Channel
- Defined in:
- lib/rumor/channel.rb
Overview
Public: A Channel is a module that can be included in any class.
It provides an ‘on’ method for matching rumors by event.
Class Attribute Summary collapse
-
.handlers ⇒ Object
Returns the value of attribute handlers.
Class Method Summary collapse
- .inherited(klass) ⇒ Object
-
.on(event, &handle) ⇒ Object
Public: Catch all events with specified name.
Instance Method Summary collapse
-
#send(rumor) ⇒ Object
Internal: Send a Rumor to this channel.
Class Attribute Details
.handlers ⇒ Object
Returns the value of attribute handlers.
8 9 10 |
# File 'lib/rumor/channel.rb', line 8 def handlers @handlers end |
Class Method Details
.inherited(klass) ⇒ Object
11 12 13 |
# File 'lib/rumor/channel.rb', line 11 def self.inherited klass klass.handlers = {} end |
.on(event, &handle) ⇒ Object
Public: Catch all events with specified name.
23 24 25 |
# File 'lib/rumor/channel.rb', line 23 def self.on event, &handle self.handlers[event] = handle end |
Instance Method Details
#send(rumor) ⇒ Object
Internal: Send a Rumor to this channel.
16 17 18 19 20 |
# File 'lib/rumor/channel.rb', line 16 def send rumor handle = self.class.handlers[rumor.event.to_sym] raise "No handler for event #{rumor.event}" unless handle self.instance_exec rumor, &handle end |