Module: Beachcomber

Defined in:
lib/beachcomber.rb,
lib/beachcomber/ffi.rb,
lib/beachcomber/types.rb,
lib/beachcomber/client.rb,
lib/beachcomber/errors.rb,
lib/beachcomber/result.rb,
lib/beachcomber/discovery.rb,
lib/beachcomber/watch_stream.rb

Overview

Beachcomber is a Ruby client for the beachcomber daemon.

The daemon caches shell-environment data (git state, hostname, battery, …) and serves it over a Unix domain socket using newline-delimited JSON.

Quick start:

require 'beachcomber'

client = Beachcomber::Client.new
result = client.get('git.branch', path: '/path/to/repo')
puts result.data if result.hit?

Persistent session (one connection, multiple queries):

client.session do |s|
s.set_context('/path/to/repo')
r1 = s.get('git.branch')
r2 = s.get('git.dirty')
end

Defined Under Namespace

Modules: Discovery, FFI, IntrospectSubject, ResponseParsing Classes: BadFlagsError, BusyError, CacheRow, Client, CombError, ConnectionFailedError, DaemonHealth, DaemonNotRunning, Error, HelloInfo, IntrospectResponse, IoError, LibraryNotFound, MissingSymbol, PanicError, ProtocolError, Reaper, Result, ServerError, Session, TimeoutError, Verdict, VersionSkewError, WatchEvent, WatchStream

Constant Summary collapse

VERSION =
'0.1.0'
DEFAULT_TIMEOUT =

seconds (100 ms) — matches libbeachcomber's own default.

0.1
KIND_TO_CLASS =

error.kind slug -> exception class. Kept in sync with libbeachcomber-ffi/src/envelope.rs's ErrorKind enum.

{
  'bad_flags' => BadFlagsError,
  'busy' => BusyError,
  'panic' => PanicError,
  'version_skew' => VersionSkewError,
  'daemon_not_running' => DaemonNotRunning,
  'connection_failed' => ConnectionFailedError,
  'io_error' => IoError,
  'parse_error' => ProtocolError,
  'server_error' => ServerError,
  'timeout' => TimeoutError,
}.freeze

Class Method Summary collapse

Class Method Details

.raise_for_error(kind, message) ⇒ Object

Raises the idiomatic exception for an envelope's error.kind/error.message. An unrecognised kind (future ABI additions) still raises CombError with that kind preserved, rather than failing to raise at all.

Raises:

  • (klass)


121
122
123
124
125
126
# File 'lib/beachcomber/errors.rb', line 121

def self.raise_for_error(kind, message)
  klass = KIND_TO_CLASS[kind]
  raise klass.new(message) if klass

  raise CombError.new(kind, message)
end