Sha256: 8cdd11b01781fbbdd6fb9d47d6a9b0661207d2a93ac7598891507a1a087cbde3

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'rubygems'
require 'vnstat/version'
require 'time'

##
# The Vnstat namespace.
module Vnstat
  autoload :Configuration, 'vnstat/configuration'
  autoload :Document, 'vnstat/document'
  autoload :Interface, 'vnstat/interface'
  autoload :InterfaceCollection, 'vnstat/interface_collection'
  autoload :Parser, 'vnstat/parser'
  autoload :Result, 'vnstat/result'
  autoload :SystemCall, 'vnstat/system_call'
  autoload :Traffic, 'vnstat/traffic'
  autoload :Utils, 'vnstat/utils'

  autoload :Error, 'vnstat/error'
  autoload :ExecutableNotFound, 'vnstat/errors/executable_not_found'
  autoload :UnknownInterface, 'vnstat/errors/unknown_interface'

  module_function

  ##
  # The configuration of the Vnstat environment.
  #
  # @return [Configuration]
  def config
    @config ||= Configuration.new
  end

  ##
  # Configures the Vnstat environment.
  #
  # @yieldparam [Configuration] config The environment configuration.
  # @return [Configuration]
  def configure
    yield(config)
    config
  end

  ##
  # Returns traffic information for the given interface.
  #
  # @param [String] id The network interface identifier.
  # @return [Interface]
  def [](id)
    interfaces[id]
  end

  ##
  # Returns traffic information for all known interfaces.
  #
  # @return [InterfaceCollection]
  def interfaces
    InterfaceCollection.open
  end

  ##
  # Returns information for the currently installed version of vnstat.
  #
  # @deprecated Please use {#cli_version} instead.
  # @return [String]
  def version
    warn '[DEPRECATION] `Vnstat.version` is deprecated. Please use ' \
         '`Vnstat.cli_version` instead.'
    cli_version
  end

  ##
  # Returns information for the currently installed version of vnstat.
  #
  # @return [String]
  def cli_version
    Utils.call_executable('-v')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vnstat-ruby-2.0.0 lib/vnstat.rb