Module: DuoRuby::Channel::HandlerMethods

Included in:
DuoRuby::Channel
Defined in:
lib/duoruby/channel/handler_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



6
7
8
# File 'lib/duoruby/channel/handler_methods.rb', line 6

def self.included(receiver)
  receiver.extend(self)
end

Instance Method Details

#channel(name) ⇒ Object



26
27
28
# File 'lib/duoruby/channel/handler_methods.rb', line 26

def channel(name)
  Namespace.new(self, name)
end

#handlersObject



10
11
12
# File 'lib/duoruby/channel/handler_methods.rb', line 10

def handlers
  @handlers ||= {}
end

#included(receiver) ⇒ Object



30
31
32
33
# File 'lib/duoruby/channel/handler_methods.rb', line 30

def included(receiver)
  receiver.__send__(:merge_handlers, handlers)
  super if defined?(super)
end

#off(event = nil, handler = nil, &block) ⇒ Object



22
23
24
# File 'lib/duoruby/channel/handler_methods.rb', line 22

def off(event = nil, handler = nil, &block)
  remove_handler(handlers, event, handler || block)
end

#on(event, &handler) ⇒ Object



14
15
16
# File 'lib/duoruby/channel/handler_methods.rb', line 14

def on(event, &handler)
  add_handler(event, false, &handler)
end

#one(event, &handler) ⇒ Object



18
19
20
# File 'lib/duoruby/channel/handler_methods.rb', line 18

def one(event, &handler)
  add_handler(event, true, &handler)
end