Module: Libuv::Listener::ClassMethods
- Defined in:
- lib/libuv/mixins/listener.rb
Instance Method Summary collapse
- #callback_funcs ⇒ Object
-
#callback_lookup ⇒ Object
Provide accessor methods to the class level instance variables.
-
#default_lookup(req, *args) ⇒ Object
This function is used to work out the instance the callback is for.
- #define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup) ⇒ Object
- #dispatch_callback(func_name, lookup, args) ⇒ Object
-
#inherited(subclass) ⇒ Object
Much like include to support inheritance properly We keep existing callbacks and inherit the lookup (as this will never clash).
Instance Method Details
#callback_funcs ⇒ Object
37 38 39 |
# File 'lib/libuv/mixins/listener.rb', line 37 def callback_funcs @callback_funcs end |
#callback_lookup ⇒ Object
Provide accessor methods to the class level instance variables
33 34 35 |
# File 'lib/libuv/mixins/listener.rb', line 33 def callback_lookup @callback_lookup end |
#default_lookup(req, *args) ⇒ Object
This function is used to work out the instance the callback is for
43 44 45 |
# File 'lib/libuv/mixins/listener.rb', line 43 def default_lookup(req, *args) req.address end |
#define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup) ⇒ Object
18 19 20 21 22 |
# File 'lib/libuv/mixins/listener.rb', line 18 def define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup) @callback_funcs[function] = FFI::Function.new(ret_val, params) do |*args| dispatch_callback(function, lookup, args) end end |
#dispatch_callback(func_name, lookup, args) ⇒ Object
12 13 14 15 16 |
# File 'lib/libuv/mixins/listener.rb', line 12 def dispatch_callback(func_name, lookup, args) instance_id = __send__(lookup, *args) inst = @callback_lookup[instance_id] inst.__send__(func_name, *args) if inst end |
#inherited(subclass) ⇒ Object
Much like include to support inheritance properly We keep existing callbacks and inherit the lookup (as this will never clash)
26 27 28 29 |
# File 'lib/libuv/mixins/listener.rb', line 26 def inherited(subclass) subclass.instance_variable_set(:@callback_funcs, {}.merge(@callback_funcs)) subclass.instance_variable_set(:@callback_lookup, @callback_lookup) end |