Module: Lich::Common::FeatureFlags

Defined in:
documented/common/feature_flags.rb

Overview

Provides persistent access to core feature flags.

Provides persistent access to core feature flags.

See Also:

Constant Summary collapse

SETTINGS_PREFIX =
'feature_flag:'
VALID_NAME_PATTERN =
/\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_settings always overrides the default.

{}.freeze

Class Method Summary collapse

Class Method Details

.enabled?(name) ⇒ Boolean

Checks if a feature flag is enabled.

Examples:

Check if a feature is enabled

Lich::Common::FeatureFlags.enabled?("new_feature")

Parameters:

  • name (String)

    the name of the feature flag

Returns:

  • (Boolean)

    true if the feature flag is enabled, false otherwise

Raises:

  • (ArgumentError)

    if the flag name is invalid



26
27
28
29
30
31
32
33
34
35
36
37
# File 'documented/common/feature_flags.rb', line 26

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

Sets the value of a feature flag.

Examples:

Set a feature flag

Lich::Common::FeatureFlags.set("new_feature", true)

Parameters:

  • name (String)

    the name of the feature flag

  • value (Boolean)

    the value to set for the feature flag

Returns:

  • (Boolean)

    true if the operation was successful, false otherwise

Raises:

  • (ArgumentError)

    if the flag name is invalid



47
48
49
50
51
52
53
54
55
# File 'documented/common/feature_flags.rb', line 47

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