Module: RailsFeatureFlip::Registry

Defined in:
lib/rails_feature_flip/registry.rb

Overview

Provides a clean API to query all registered features.

Features are stored in Rails.configuration.x.features (an OrderedOptions hash). This module wraps that hash with convenience methods.

Examples:

RailsFeatureFlip::Registry.all    # => { chat: #<Features::ChatFeature>, ... }
RailsFeatureFlip::Registry.names  # => [:chat, :billing]
RailsFeatureFlip::Registry.find(:chat) # => #<Features::ChatFeature>

Class Method Summary collapse

Class Method Details

.all ⇒ Hash{Symbol => Object}

Returns all registered features as a hash.

Returns:

  • (Hash{Symbol => Object})


17
18
19
# File 'lib/rails_feature_flip/registry.rb', line 17

def self.all
  features_store.to_h
end

.find(name) ⇒ Object

Finds a feature by name.

Parameters:

  • name (Symbol, String) —

    the feature name

Returns:

  • (Object) —

    the feature instance

Raises:



33
34
35
36
37
38
# File 'lib/rails_feature_flip/registry.rb', line 33

def self.find(name)
  feature = features_store[name.to_sym]
  raise RailsFeatureFlip::Error, "Feature '#{name}' is not registered" if feature.nil?

  feature
end

.names ⇒ Array<Symbol>

Returns the names of all registered features.

Returns:

  • (Array<Symbol>)


24
25
26
# File 'lib/rails_feature_flip/registry.rb', line 24

def self.names
  features_store.keys
end