Ravn module

Ravn base library.

SBIR DATA RIGHTS

Contract No. FA8649-19-9-9031 Contractor Name: Ravn Inc. Contractor Address: 548 Market Street, PMB 80382, San Francisco, CA 94104, United States Expiration of SBIR Data Rights Period: 7 August 2039

The Government’s rights to use, modify, reproduce, release, perform, display, or disclose technical data or computer software marked with this legend are restricted during the period shown as provided in paragraph (b)(4) of the Rights in Noncommercial Technical Data and Computer Software—Small Business Innovation Research (SBIR) Program clause contained in the above identified contract. No restrictions apply after the expiration date shown above. Any reproduction of technical data, computer software, or portions thereof marked with this legend must also reproduce the markings.

Constants

CONFIG_ENV

The name of the environment variable which can be used to set the config path

DEFAULT_CONFIG_FILE

The name of the config file that’s loaded if none is specified.

DEFAULT_DATA_DIR

The path to the data directory for the Ravn library. rubocop:disable Layout/IndentationWidth

DEVICE_ID_BYTESIZE

The number of bytes in a device ID

LOCAL_CONFIG_FILE

The name of the config file for local overrides.

VERSION

Package version

Public Class Methods

after_fork()

Define a blockt that is run by the child process after a Process.fork.

# File lib/ravn.rb, line 89
define_hook :after_fork
before_fork()

Define a block that is run before a Process.fork

# File lib/ravn.rb, line 84
define_hook :before_fork
config()

Get the loaded config (a Configurability::Config object)

# File lib/ravn.rb, line 120
def self::config
        Configurability.loaded_config
end
config_loaded?()

Returns true if the configuration has been loaded at least once.

# File lib/ravn.rb, line 126
def self::config_loaded?
        return self.config ? true : false
end
data_dir()

The Pathname of the gem’s data directory

# File lib/ravn.rb, line 100
singleton_attr_accessor :data_dir
default_config()

Return the configuration defaults as a Configurability::Config object.

# File lib/ravn.rb, line 154
def self::default_config
        return Configurability.default_config
end
device_id()

Return the unique 8-byte device ID for the current host.

# File lib/ravn.rb, line 189
def self::device_id
        return @device_id ||= begin
                self.log.info "Device ID file is %s" % [ self.device_id_file ]
                if self.device_id_file.readable?
                        self.device_id_file.read( encoding: 'us-ascii' ).chomp
                else
                        self.log.warn "Device ID file is not readable; attempting to write one"
                        device_id = SecureRandom.hex( DEVICE_ID_BYTESIZE )
                        self.device_id_file.open( File::EXCL|File::WRONLY|File::CREAT, encoding: 'us-ascii' ) do |fh|
                                fh.puts( device_id )
                        end
                        device_id
                end
        end
end
load_config( config_file=nil, defaults=nil )

Load the specified config_file, install the config in all objects with Configurability, and call any callbacks registered via after_configure.

# File lib/ravn.rb, line 133
def self::load_config( config_file=nil, defaults=nil )
        config_file ||= ENV[ CONFIG_ENV ]
        config_file ||= LOCAL_CONFIG_FILE if LOCAL_CONFIG_FILE.exist?
        config_file ||= DEFAULT_CONFIG_FILE
        config_file = Pathname( config_file ) if config_file

        defaults ||= Configurability.gather_defaults

        config = if config_file&.exist?
                        self.log.info "Loading config from %p with defaults for sections: %p." %
                                [ config_file, defaults.keys ]
                        Configurability::Config.load( config_file, defaults )
                else
                        Configurability.default_config
                end

        config.install
end
monotonic_time()

Return a time from the monotonic clock.

# File lib/ravn.rb, line 170
def self::monotonic_time
        return Process.clock_gettime( Process::CLOCK_MONOTONIC )
end
time()

Return the time from the clock used to coordinate network nodes and messages.

# File lib/ravn.rb, line 164
def self::time
        return Process.clock_gettime( Process::CLOCK_REALTIME )
end
uuid()

The global UUID object for generating new UUIDs

# File lib/ravn.rb, line 94
singleton_attr_reader :uuid