Module: FFI::Libfuse::Callbacks

Included in:
FuseCallbacks
Defined in:
lib/ffi/libfuse/callbacks.rb

Overview

Methods to register callbacks and wrappers

Instance Method Summary collapse

Instance Method Details

#register(method, wrappers = [], &block) ⇒ Object

Note:

wrappers are defined in inside out order

Registers block as a callback method

Parameters:

  • method (Symbol)

    the callback being registered

  • wrappers (Array<Proc,Hash<:wrapper,:excludes>,Object>) (defaults to: [])

    with each entry being

    • a Proc(method, *args, &block)

      either handling the callback itself or yielding *args (possibly after manipulation) onwards to &block. Do not include method in the yield args!

    • a Hash with keys

      • wrapper: [Proc] as above
      • excludes: [Array] names of methods that the proc should not apply to. Useful when registering the same list of wrappers for many methods
    • an Object responding to #method(*args,&block)

  • block (Proc)

    if provided is used as the innermost block to handle the callback - equivalent to being the first entry in wrappers list



27
28
29
30
31
32
33
34
# File 'lib/ffi/libfuse/callbacks.rb', line 27

def register(method, wrappers = [], &block)
  callback = wrappers.each.inject(block) do |b, w|
    next wrap_callback(method, **w, &b) if w.is_a?(Hash)

    wrap_callback(method, w, &b)
  end
  send(:[]=, method, callback)
end