Module: Shipeasy
- Defined in:
- lib/shipeasy/config.rb,
lib/shipeasy-sdk.rb,
lib/shipeasy/sdk/eval.rb,
lib/shipeasy/sdk/anon_id.rb,
lib/shipeasy/sdk/murmur3.rb,
lib/shipeasy/sdk/railtie.rb,
lib/shipeasy/sdk/version.rb,
lib/shipeasy/i18n/railtie.rb,
lib/shipeasy/sdk/telemetry.rb,
lib/shipeasy/sdk/flags_client.rb,
lib/shipeasy/i18n/view_helpers.rb,
lib/shipeasy/i18n/label_fetcher.rb,
lib/shipeasy/sdk/rack_middleware.rb
Overview
Single configuration object for the Shipeasy gem.
Covers both subsystems:
- SDK / experimentation (api_key, base_url) — drives FlagsClient
- i18n / string manager (public_key, profile, cdn_base_url, ...) — drives
the Rails view helpers and label fetcher
Usage:
Shipeasy.configure do |c|
c.api_key = ENV["SHIPEASY_SERVER_KEY"]
c.public_key = ENV["SHIPEASY_CLIENT_KEY"]
c.profile = "default"
end
Anything not set falls back to the defaults below. The same Shipeasy.config is read by FlagsClient and the Rails helpers, so there is one place to point environment variables at.
Defined Under Namespace
Modules: I18n, SDK Classes: Configuration
Class Method Summary collapse
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
-
.flags ⇒ Object
Lazy, fork-safe singleton FlagsClient.
-
.reset_config! ⇒ Object
Reset the config back to defaults — primarily for tests.
Class Method Details
.config ⇒ Object
44 45 46 |
# File 'lib/shipeasy/config.rb', line 44 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
48 49 50 |
# File 'lib/shipeasy/config.rb', line 48 def configure yield config end |
.flags ⇒ Object
Lazy, fork-safe singleton FlagsClient. The first call from each process spawns a fresh client + poll thread — including post-fork workers under Puma’s preload_app!. Callers can ‘Shipeasy.flags.get_flag(…)` straight from a controller without holding a constant or worrying about `before_worker_boot` hooks.
Initializers stay minimal:
# config/initializers/shipeasy.rb
Shipeasy.configure { |c| c.api_key = ENV["SHIPEASY_SERVER_KEY"] }
The first request that touches ‘Shipeasy.flags.*` triggers init(). For serverless / Lambda where you want a single fetch with no thread, build the client explicitly: `Shipeasy::SDK::FlagsClient.new(…).init_once`.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/shipeasy/config.rb', line 74 def flags pid = Process.pid if @flags && @flags_pid != pid # Post-fork: parent's poll thread didn't survive. Don't destroy # @flags (its mutex/state is invalid in this child anyway); just # rebuild from scratch. @flags = nil end @flags ||= begin @flags_pid = pid client = SDK::FlagsClient.new( api_key: config.api_key, base_url: config.base_url, ) client.init client end end |
.reset_config! ⇒ Object
Reset the config back to defaults — primarily for tests.
53 54 55 56 57 58 |
# File 'lib/shipeasy/config.rb', line 53 def reset_config! @config = nil @flags_pid = nil @flags&.destroy @flags = nil end |