Liteguard Ruby SDK

Ruby SDK Gem Version

Installation

gem install liteguard

Or add to your Gemfile:

gem "liteguard"

Requires Ruby 3.1+.

Quick Start

require "liteguard"

client = Liteguard::Client.new(
  "pct-...",
  environment: "env-production"
)
client.start

scope = client.create_scope(user_id: "user-123", plan: "pro")

if scope.open?("payments.checkout")
  # ...
end

client.shutdown

Primary API

  • Liteguard::Client.new(project_client_token, **options) creates a client.
  • client.start fetches the initial bundle and starts refresh and flush workers.
  • client.create_scope(**properties) creates an immutable scope.
  • scope.open?(name, **options) evaluates locally.
  • scope.evaluate(name, **options) returns a GuardDecision with the full evaluation result.
  • scope.execute_if_open(name, **options) { ... } measures guarded work.
  • scope.start_execution creates an execution correlation handle.
  • scope.bind_protected_context(**protected_context) derives a protected scope.
  • scope.properties returns the current property bag for transport.
  • client.flush flushes buffered telemetry.
  • client.shutdown flushes and stops background work.

Convenience helpers

For server applications that want request-scoped context propagation:

  • client.with_scope(scope) { ... } runs a block with scope as the active scope, isolated via Thread.current.
  • client.active_scope returns the scope bound to the current thread.
  • client.with_properties(properties) { ... } derives and activates a scope with additional properties.
  • client.with_protected_context(protected_context) { ... } derives and activates a protected scope.

Notes

  • Evaluation is local after the initial bundle fetch.
  • Prefer explicit client and scope usage.
  • Unadopted guards default open and emit no signals.
  • The convenience helpers above also serve as infrastructure for auto-instrumentation of third-party dependencies. See the Liteguard CLI for build-time instrumentation.

Development

make test-ruby

License

Apache 2.0 see LICENSE.