Sha256: b07572a82780e7ca6addaaca547616aee788a22a88826581c325482514ad0fd3

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Libvirt
  module Util
    class << self

      def logger=(logger)
        @logger = logger
      end

      def logger
        @logger
      end

      def log(severity, prog = nil, &block)
        return if @logger.nil?
        @logger.public_send(severity, prog, &block)
      end

      def library_path
        %w(libvirt libvirt.so.0)
      end

      # @param [Integer] version_number ulong
      def parse_version(version_number)
        major = version_number / 1_000_000
        minor = (version_number - major * 1_000_000) / 1_000
        release = version_number - major * 1_000_000 - minor * 1_000
        "#{major}.#{minor}.#{release}"
      end

      # @param enum [FFI::Enum]
      # @param value [Symbol, Integer]
      # @return [Array] event_id, event_id_sym
      # @raise ArgumentError
      def parse_enum(enum, value)
        if value.is_a?(Symbol)
          raise ArgumentError, 'invalid enum value' unless enum.symbols.include?(value)
          return [enum.find(value), value]
        end

        raise ArgumentError, 'invalid enum value' unless enum.symbol_map.values.include?(value)
        [value, enum.symbol_map[value]]
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
libvirt_ffi-0.4.1 lib/libvirt/util.rb
libvirt_ffi-0.4.0 lib/libvirt/util.rb