Sha256: cc24f31f033e1c31ebf6aa71113a7aa4aaafc123b3d64103d2907b18c1e30a9c

Contents?: true

Size: 721 Bytes

Versions: 11

Compression:

Stored size: 721 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

    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

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
libvirt_ffi-0.7.0 lib/libvirt/base_info.rb
libvirt_ffi-0.6.2 lib/libvirt/base_info.rb
libvirt_ffi-0.6.1 lib/libvirt/base_info.rb
libvirt_ffi-0.6.0 lib/libvirt/base_info.rb
libvirt_ffi-0.5.6 lib/libvirt/base_info.rb
libvirt_ffi-0.5.5 lib/libvirt/base_info.rb
libvirt_ffi-0.5.4 lib/libvirt/base_info.rb
libvirt_ffi-0.5.3 lib/libvirt/base_info.rb
libvirt_ffi-0.5.2 lib/libvirt/base_info.rb
libvirt_ffi-0.5.1 lib/libvirt/base_info.rb
libvirt_ffi-0.5.0 lib/libvirt/base_info.rb