Sha256: 6906d610f299ef93fc380f166586f7b7e74136cc93682d96e5a19ddc10ea6787

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

module Libvirt
  module Ruby
    class Util
      extend FFI::Library

      def self.method_missing(method, *args)
        args.flatten!
        return_type = args.delete(args.last)
        dispatcher(method, args, return_type)
      end

      def self.dispatcher(method, args = [], return_type = nil)
        unless not_direct_call?
          warn "[DEPRECATION] `dispatcher` is deprecated.  Please call the function directly instead."
        end
        begin
          ffi_lib "libvirt"
          attach_function (self.klass + method.to_s), (self.klass + method.to_s), args, return_type
          send (self.klass + method.to_s), args
        rescue FFI::NotFoundError
          raise Libvirt::Ruby::Exceptions::InvalidFunction.new(self.klass + method.to_s)
        rescue LoadError
          raise Libvirt::Ruby::Exceptions::MissingLib
        end
      end

      private

      def self.not_direct_call?
        caller[1][/`.*'/][1..-2] == 'method_missing'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
libvirt-ruby-0.0.5 lib/libvirt-ruby/util.rb