Sha256: 3855a68dc75bb3ac1eb9c887f0ce37da5b16383099b20760cfb6fc5879b83407
Contents?: true
Size: 878 Bytes
Versions: 2
Compression:
Stored size: 878 Bytes
Contents
# frozen_string_literal: true module Libvirt class BaseInfo # Abstract Base class for info class << self attr_accessor :_struct_class # @param [Class<FFI::Struct>] def struct_class(klass) self._struct_class = klass klass.members.each do |attr| define_method(attr) { @struct[attr] } end end end # @param pointer [FFI::Pointer] 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 # @param attr [Symbol] # @return [Object, nil] def [](attr) @struct[attr] end # @return [Hash] def to_h @struct.members.map { |attr| [attr, @struct[attr]] }.to_h end def to_ptr @struct.to_ptr end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
libvirt_ffi-0.8.1 | lib/libvirt/base_info.rb |
libvirt_ffi-0.8.0 | lib/libvirt/base_info.rb |