Module: ToggleFleet

Defined in:
lib/togglefleet.rb,
lib/togglefleet/version.rb

Overview

ToggleFleet — cloud feature flags for Ruby.

Built from the ground up (Flipper’s gate model as the reference, none of its code). Design goals: evaluate flags LOCALLY so there is zero network on the hot path, refresh the config in the background with conditional (ETag) requests, and fail safe.

ToggleFleet.configure { |c| c.sdk_key = ENV["TOGGLEFLEET_SDK_KEY"] }
ToggleFleet.register_group(:admins) { |user| user.admin? }
ToggleFleet.start                      # begin background refresh (optional but recommended)

ToggleFleet.enabled?(:checkout_v2, actor: current_user)   # => true / false

Defined Under Namespace

Classes: Client, Configuration, Error

Constant Summary collapse

GATES =

The five gates, evaluated in order — first match wins (mirrors the server exactly).

%i[boolean actor group percentage_of_actors percentage_of_time].freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.all(**opts) ⇒ Object



205
# File 'lib/togglefleet.rb', line 205

def all(**opts) = client.all(**opts)

.clientObject



197
198
199
# File 'lib/togglefleet.rb', line 197

def client
  @client ||= Client.new(config)
end

.configObject



193
194
195
# File 'lib/togglefleet.rb', line 193

def config
  @config ||= Configuration.new
end

.configure {|@config| ... } ⇒ Object

Yields:



186
187
188
189
190
191
# File 'lib/togglefleet.rb', line 186

def configure
  @config = Configuration.new
  yield @config if block_given?
  @client = Client.new(@config)
  @config
end

.enabled?(flag, **opts) ⇒ Boolean

Returns:

  • (Boolean)


204
# File 'lib/togglefleet.rb', line 204

def enabled?(flag, **opts) = client.enabled?(flag, **opts)

.register_group(name, &block) ⇒ Object



201
# File 'lib/togglefleet.rb', line 201

def register_group(name, &block) = client.register_group(name, &block)

.reset!Object

mostly for tests



208
209
210
211
# File 'lib/togglefleet.rb', line 208

def reset!
  @config = nil
  @client = nil
end

.startObject



202
# File 'lib/togglefleet.rb', line 202

def start = client.start

.syncObject



203
# File 'lib/togglefleet.rb', line 203

def sync = client.sync