Module: CruFlags
- Defined in:
- lib/cru_flags.rb,
lib/cru_flags/client.rb,
lib/cru_flags/errors.rb,
lib/cru_flags/fetcher.rb,
lib/cru_flags/railtie.rb,
lib/cru_flags/version.rb,
lib/cru_flags/document.rb,
lib/cru_flags/flipper_adapter.rb
Overview
Module-level singleton — the 99% path (design doc §3.1). Requiring this file does nothing: no env read, no socket, no thread.
Defined Under Namespace
Modules: Document, Fetcher Classes: Client, Error, FetchError, FlipperAdapter, ParseError, Railtie, ReadOnlyError
Constant Summary collapse
- ENV_VAR =
"CRU_FLAGS_URL"- VERSION =
"0.1.2"
Class Method Summary collapse
-
.client ⇒ Object
The env read happens inside Client (Client.url_from_env), so the singleton and a hand-rolled
Client.newshare one normalization rather than two copies that can drift. -
.close ⇒ Object
Nil-safe on the ivar, like reset!: going through the memoizing reader would BUILD (and validate) a singleton just to close it, leaving a permanently-closed client memoized — and emitting the invalid-URL warning at shutdown for an app that never used flags at all.
- .enabled?(name) ⇒ Boolean
-
.flipper_adapter ⇒ Object
The read-only Flipper adapter (design doc §5), memoized and bound to the singleton client.
- .ready(timeout: nil) ⇒ Object
- .refresh(force: false) ⇒ Object
-
.reset! ⇒ Object
Test hook, not public API: closes and discards the singleton so the next call re-reads the environment.
- .snapshot ⇒ Object
Class Method Details
.client ⇒ Object
The env read happens inside Client (Client.url_from_env), so the
singleton and a hand-rolled Client.new share one normalization
rather than two copies that can drift.
23 24 25 |
# File 'lib/cru_flags.rb', line 23 def client @client || @client_mutex.synchronize { @client ||= Client.new } end |
.close ⇒ Object
Nil-safe on the ivar, like reset!: going through the memoizing reader would BUILD (and validate) a singleton just to close it, leaving a permanently-closed client memoized — and emitting the invalid-URL warning at shutdown for an app that never used flags at all.
39 |
# File 'lib/cru_flags.rb', line 39 def close = @client&.close |
.enabled?(name) ⇒ Boolean
27 |
# File 'lib/cru_flags.rb', line 27 def enabled?(name) = client.enabled?(name) |
.flipper_adapter ⇒ Object
The read-only Flipper adapter (design doc §5), memoized and bound to
the singleton client. flipper is required lazily here (not at the
top of this file) so requiring "cru_flags" alone stays flipper-free.
44 45 46 47 48 49 50 51 |
# File 'lib/cru_flags.rb', line 44 def flipper_adapter @flipper_adapter || @flipper_adapter_mutex.synchronize do @flipper_adapter ||= begin require_relative "cru_flags/flipper_adapter" FlipperAdapter.new(client) end end end |
.ready(timeout: nil) ⇒ Object
29 |
# File 'lib/cru_flags.rb', line 29 def ready(timeout: nil) = client.ready(timeout:) |
.refresh(force: false) ⇒ Object
33 |
# File 'lib/cru_flags.rb', line 33 def refresh(force: false) = client.refresh(force:) |
.reset! ⇒ Object
Test hook, not public API: closes and discards the singleton so the next call re-reads the environment.
55 56 57 58 59 60 61 |
# File 'lib/cru_flags.rb', line 55 def reset! @client_mutex.synchronize do @client&.close @client = nil end @flipper_adapter_mutex.synchronize { @flipper_adapter = nil } end |
.snapshot ⇒ Object
31 |
# File 'lib/cru_flags.rb', line 31 def snapshot = client.snapshot |