Sha256: 4953e839fe10baa209fd65464ab2d7cfabaa5ced20eb8fe3b833c1df7d4d987d

Contents?: true

Size: 972 Bytes

Versions: 3

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

require_relative '../fuse_context'

module FFI
  module Libfuse
    module Adapter
      # Wrapper module to inject {FuseContext} as first arg to each callback method (except :destroy)
      #
      # {ThreadLocalContext} may be a less intrusive means to make the context available to callbacks
      module Context
        # @!visibility private
        def fuse_wrappers(*wrappers)
          wrappers.unshift(
            {
              wrapper: proc { |_fm, *args, **_, &b| self.class.context_callback(*args, &b) },
              excludes: %i[destroy]
            }
          )
          return wrappers unless defined?(super)

          super(*wrappers)
        end

        module_function

        # @yieldparam [FuseContext] ctx
        # @yieldparam [Array] *args
        def context_callback(*args)
          ctx = FuseContext.get
          ctx = nil if ctx.null?
          yield ctx, *args
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-libfuse-0.0.1.rctest12 lib/ffi/libfuse/adapter/context.rb
ffi-libfuse-0.0.1.rctest11 lib/ffi/libfuse/adapter/context.rb
ffi-libfuse-0.0.1.pre lib/ffi/libfuse/adapter/context.rb