Class: DuoRuby::Channel::Namespace
- Inherits:
-
Object
- Object
- DuoRuby::Channel::Namespace
- Defined in:
- lib/duoruby/channel/namespace.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(target, name) ⇒ Namespace
constructor
A new instance of Namespace.
- #off(event = nil, handler = nil, &block) ⇒ Object
- #on(event, &handler) ⇒ Object
- #one(event, &handler) ⇒ Object
- #send(event, **params) ⇒ Object
- #trigger(event, *args, **params) ⇒ Object
Constructor Details
#initialize(target, name) ⇒ Namespace
Returns a new instance of Namespace.
14 15 16 17 |
# File 'lib/duoruby/channel/namespace.rb', line 14 def initialize(target, name) @target = target @name = name.to_s end |
Class Method Details
.call(target, name, &block) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/duoruby/channel/namespace.rb', line 6 def self.call(target, name, &block) namespace = new(target, name) return namespace unless block return block.call(namespace) if block.arity.positive? namespace.instance_exec(&block) end |
Instance Method Details
#off(event = nil, handler = nil, &block) ⇒ Object
27 28 29 30 31 |
# File 'lib/duoruby/channel/namespace.rb', line 27 def off(event = nil, handler = nil, &block) return @target.off unless event @target.off(namespaced(event), handler, &block) end |
#on(event, &handler) ⇒ Object
19 20 21 |
# File 'lib/duoruby/channel/namespace.rb', line 19 def on(event, &handler) @target.on(namespaced(event), &handler) end |
#one(event, &handler) ⇒ Object
23 24 25 |
# File 'lib/duoruby/channel/namespace.rb', line 23 def one(event, &handler) @target.one(namespaced(event), &handler) end |
#send(event, **params) ⇒ Object
37 38 39 |
# File 'lib/duoruby/channel/namespace.rb', line 37 def send(event, **params) @target.send(namespaced(event), **params) end |
#trigger(event, *args, **params) ⇒ Object
33 34 35 |
# File 'lib/duoruby/channel/namespace.rb', line 33 def trigger(event, *args, **params) @target.trigger(namespaced(event), *args, **params) end |