Module: Libvirt::Ruby

Extended by:
FFI::Library
Defined in:
lib/libvirt-ruby.rb,
lib/libvirt-ruby/version.rb,
lib/libvirt-ruby/exceptions.rb,
lib/libvirt-ruby/exceptions/wrong_call.rb,
lib/libvirt-ruby/exceptions/missing_lib.rb,
lib/libvirt-ruby/exceptions/invalid_function.rb,
lib/libvirt-ruby/exceptions/no_return_parameter.rb

Defined Under Namespace

Modules: Exceptions

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.dispatcher(method, args = [], return_type = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/libvirt-ruby.rb', line 19

def self.dispatcher(method, args = [], return_type = nil)
  raise Libvirt::Ruby::Exceptions::WrongCall unless not_direct_call?
  begin
    ffi_lib "libvirt"
    attach_function method.to_s, method.to_s, args, return_type
    send method.to_s, args
  rescue FFI::NotFoundError
    raise Libvirt::Ruby::Exceptions::InvalidFunction.new(method.to_s)
  rescue LoadError
    raise Libvirt::Ruby::Exceptions::MissingLib
  end
end

.method_missing(method, *args) ⇒ Object



10
11
12
13
14
15
# File 'lib/libvirt-ruby.rb', line 10

def self.method_missing(method, *args)
  args.flatten!
  return_type = args.delete(args.last)
  raise Libvirt::Ruby::Exceptions::NoReturnParameter unless return_type
  dispatcher(method, args, return_type)
end

.not_direct_call?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/libvirt-ruby.rb', line 32

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