Class: Libvirt::BaseInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/libvirt/base_info.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ BaseInfo

Returns a new instance of BaseInfo.

Parameters:

  • pointer (FFI::Pointer)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/libvirt/base_info.rb', line 20

def initialize(pointer)
  raise ArgumentError, "Can't initialize base class #{self.class}" if self.class == BaseInfo

  @ptr = pointer
  @struct = self.class._struct_class.new(pointer)
end

Class Attribute Details

._struct_classObject

Returns the value of attribute _struct_class.



8
9
10
# File 'lib/libvirt/base_info.rb', line 8

def _struct_class
  @_struct_class
end

Class Method Details

.struct_class(klass) ⇒ Object

Parameters:

  • (Class<FFI::Struct>)


11
12
13
14
15
16
# File 'lib/libvirt/base_info.rb', line 11

def struct_class(klass)
  self._struct_class = klass
  klass.members.each do |attr|
    define_method(attr) { @struct[attr] }
  end
end

Instance Method Details

#[](attr) ⇒ Object?

Parameters:

  • attr (Symbol)

Returns:

  • (Object, nil)


29
30
31
# File 'lib/libvirt/base_info.rb', line 29

def [](attr)
  @struct[attr]
end

#to_hHash

Returns:

  • (Hash)


34
35
36
# File 'lib/libvirt/base_info.rb', line 34

def to_h
  @struct.members.map { |attr| [attr, @struct[attr]] }.to_h
end

#to_ptrObject



38
39
40
# File 'lib/libvirt/base_info.rb', line 38

def to_ptr
  @struct.to_ptr
end