Module: Lich::Common::FeatureFlags
- Defined in:
- documented/common/feature_flags.rb
Overview
Provides persistent access to core feature flags.
Feature flags are stored in the lich_settings table using keys with the
feature_flag: prefix. Missing keys fall back to values defined in
DEFAULTS, or false when no explicit default is registered.
This module intentionally exposes a minimal surface area:
- FeatureFlags.enabled? reads a flag with safe fallback behavior
- FeatureFlags.set persists a flag value for future reads
Keeping the API narrow makes it easier to adopt feature flags incrementally without introducing a second configuration framework.
Constant Summary collapse
- SETTINGS_PREFIX =
'feature_flag:'- VALID_NAME_PATTERN =
Pattern that validates normalized feature flag names.
Flags must be lowercase alphanumeric or underscore, with no spaces or special characters. This ensures portable flag names that can be serialized as database keys without escaping.
/\A[a-z0-9_]+\z/- DEFAULTS =
Defines default values for known feature flags.
Add new flags here as infrastructure is adopted by production code. The persisted value in
lich_settingsalways overrides the default. {}.freeze
Class Method Summary collapse
-
.enabled?(name) ⇒ Boolean
Returns whether a feature flag is enabled.
-
.set(name, value) ⇒ Boolean
Persists a feature flag value in
lich_settings.
Class Method Details
.enabled?(name) ⇒ Boolean
Returns whether a feature flag is enabled.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'documented/common/feature_flags.rb', line 60 def self.enabled?(name) flag_name = validate_flag_name!(normalize_name(name)) begin stored = read_flag(flag_name) return default_for(flag_name) if stored.nil? truthy?(stored) rescue StandardError => e log_failure('read', flag_name, e) default_for(flag_name) end end |
.set(name, value) ⇒ Boolean
Persists a feature flag value in lich_settings.
Values are stored as strings to match the existing lich_settings
storage model. Callers should prefer booleans, but any value responding
to #to_s is accepted and later interpreted by enabled?.
84 85 86 87 88 89 90 91 92 |
# File 'documented/common/feature_flags.rb', line 84 def self.set(name, value) flag_name = validate_flag_name!(normalize_name(name)) begin write_flag(flag_name, value) rescue StandardError => e log_failure('write', flag_name, e) false end end |