Module: OpenLoam::Features
- Defined in:
- lib/open_loam/features.rb
Overview
Runtime feature toggles: is a capability turned ON for this tenant right now.
OpenLoam::Features.on?(:beta_dashboard) # for the current tenant
OpenLoam::Features.enable(:beta_dashboard) # this tenant only
OpenLoam::Features.enable(:beta_dashboard, scope: :global) # everyone
OpenLoam::Features.disable(:beta_dashboard)
OpenLoam::Features.reset(:beta_dashboard) # drop the override → default
A flag gates a CAPABILITY (is this feature live for the tenant), which is orthogonal to a policy — that gates a PERSON (may this user act). The two coexist: a manager may be allowed to approve reports AND the approvals feature may be switched off for their tenant during a rollout.
This is deliberately a thin wrapper over OpenLoam::Configs: a flag is a boolean
setting with the same override → global → declared-default resolution, so it
reuses that store (no new table) and its per-request cache. Flags live under
the reserved features. key prefix and get their own admin screen, because
"flags" and "settings" are different mental models even sharing storage.
Constant Summary collapse
- PREFIX =
"features.".freeze
Class Method Summary collapse
-
.declared ⇒ Object
Every declared flag, sorted — the admin lists these whether or not a row exists yet, so a flag is visible the moment it is declared.
-
.default_for(name) ⇒ Object
The declared-default state of a flag (false for an unknown one), used as the last resort when there is no override and no global row.
- .description(name) ⇒ Object
- .disable(name, scope: :tenant) ⇒ Object
-
.enable(name, scope: :tenant) ⇒ Object
Flip a flag on.
- .off?(name) ⇒ Boolean
- .on?(name) ⇒ Boolean
- .overridden?(name) ⇒ Boolean
-
.reset(name) ⇒ Object
Drop the current tenant's override so the flag falls back to the global state / declared default.
Class Method Details
.declared ⇒ Object
Every declared flag, sorted — the admin lists these whether or not a row exists yet, so a flag is visible the moment it is declared.
54 55 56 |
# File 'lib/open_loam/features.rb', line 54 def declared OpenLoam.feature_defaults.keys.sort end |
.default_for(name) ⇒ Object
The declared-default state of a flag (false for an unknown one), used as the last resort when there is no override and no global row.
64 65 66 |
# File 'lib/open_loam/features.rb', line 64 def default_for(name) !!OpenLoam.feature_defaults.dig(name.to_s, :default) end |
.description(name) ⇒ Object
58 59 60 |
# File 'lib/open_loam/features.rb', line 58 def description(name) OpenLoam.feature_defaults.dig(name.to_s, :description) end |
.disable(name, scope: :tenant) ⇒ Object
38 39 40 |
# File 'lib/open_loam/features.rb', line 38 def disable(name, scope: :tenant) OpenLoam::Configs.set(key_for(name), false, scope: scope) end |
.enable(name, scope: :tenant) ⇒ Object
Flip a flag on. scope: :tenant (default) overrides for the current tenant and requires a tenant in context; scope: :global sets the app-wide state.
34 35 36 |
# File 'lib/open_loam/features.rb', line 34 def enable(name, scope: :tenant) OpenLoam::Configs.set(key_for(name), true, scope: scope) end |
.off?(name) ⇒ Boolean
28 29 30 |
# File 'lib/open_loam/features.rb', line 28 def off?(name) !on?(name) end |
.on?(name) ⇒ Boolean
24 25 26 |
# File 'lib/open_loam/features.rb', line 24 def on?(name) !!OpenLoam::Configs.get(key_for(name), default: default_for(name)) end |
.overridden?(name) ⇒ Boolean
48 49 50 |
# File 'lib/open_loam/features.rb', line 48 def overridden?(name) OpenLoam::Configs.overridden?(key_for(name)) end |