Module: Mycel::Callbacks
- Included in:
- Mycel::Channel::Command, Mycel::Channel::Hub, Mycel::Channel::Job, Mycel::Channel::Session, Transport::Mixin::Callback::Client, Transport::Mixin::Callback::Server
- Defined in:
- lib/mycel.rb
Overview
Cross-cutting: Callbacks
Instance Method Summary collapse
Instance Method Details
#__mycel_callback_handlers__ ⇒ Object
63 64 65 |
# File 'lib/mycel.rb', line 63 def __mycel_callback_handlers__ @__mycel_callback_handlers__ ||= Hash.new end |
#callback(sym) ⇒ Object
72 73 74 75 76 |
# File 'lib/mycel.rb', line 72 def callback(sym, ...) handler = __mycel_callback_handlers__[sym] || (method((sym.to_s + '_callback').to_sym) rescue nil) handler&.call(...) end |
#on(sym, &block) ⇒ Object
67 68 69 70 |
# File 'lib/mycel.rb', line 67 def on(sym, &block) raise(ArgumentError) unless sym.is_a?(Symbol) __mycel_callback_handlers__[sym] = block end |