Sha256: f1f2db7314def6f6aa553e467eac73d743130f903c8e9b57a4a193bf836264de

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require_relative '../fuse_operations'

module FFI
  module Libfuse
    module Test
      # A FuseOperations that holds callback procs in a Hash rather than FFI objects and allows for direct invocation of
      # callback methods
      # @!parse FuseOperations
      class Operations
        include FuseCallbacks

        def initialize(delegate:, fuse_wrappers: [])
          @callbacks = {}
          initialize_callbacks(delegate: delegate, wrappers: fuse_wrappers)
        end

        # @!visibility private
        def [](member)
          @callbacks[member]
        end

        # @!visibility private
        def []=(member, value)
          @callbacks[member] = value
        end

        # @!visibility private
        def members
          FuseOperations.members
        end

        private

        # Allow the fuse operations to be called directly - useful for testing
        # @todo some fancy wrapper to convert tests using Fuse2 signatures when Fuse3 is the loaded library
        #   and vice-versa
        def method_missing(method, *args)
          callback = callback?(method) && self[method]
          return super unless callback

          callback.call(*args)
        end

        def respond_to_missing?(method, _private = false)
          self[method] && callback?(method)
        end

        def callback?(method)
          callback_members.include?(method)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ffi-libfuse-0.1.0.rc20220550 lib/ffi/libfuse/test/operations.rb
ffi-libfuse-0.0.1.rctest12 lib/ffi/libfuse/test/operations.rb
ffi-libfuse-0.0.1.rctest11 lib/ffi/libfuse/test/operations.rb
ffi-libfuse-0.0.1.pre lib/ffi/libfuse/test/operations.rb