Liteguard Ruby SDK
- Website: liteguard.io
- Project Page: https://github.com/liteguard/liteguard
- Issues: https://github.com/liteguard/liteguard/issues/new
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.startfetches 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 aGuardDecisionwith the full evaluation result.scope.execute_if_open(name, **options) { ... }measures guarded work.scope.start_executioncreates an execution correlation handle.scope.bind_protected_context(**protected_context)derives a protected scope.scope.propertiesreturns the current property bag for transport.client.flushflushes buffered telemetry.client.shutdownflushes and stops background work.
Convenience helpers
For server applications that want request-scoped context propagation:
client.with_scope(scope) { ... }runs a block withscopeas the active scope, isolated viaThread.current.client.active_scopereturns 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.