Class: Togls::FeatureRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/togls/feature_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeatureRegistry

Returns a new instance of FeatureRegistry.



3
4
5
6
# File 'lib/togls/feature_registry.rb', line 3

def initialize
  @registry = {}
  @default_feature = Feature.new(:default).tap {|f| f.on(Rule.new { false }) }
end

Class Method Details

.create(&features) ⇒ Object



8
9
10
11
12
# File 'lib/togls/feature_registry.rb', line 8

def self.create(&features)
  registry = self.new
  registry.instance_eval(&features) 
  registry
end

Instance Method Details

#feature(tag) ⇒ Object



14
15
16
# File 'lib/togls/feature_registry.rb', line 14

def feature(tag)
  @registry[tag.to_sym] = Feature.new(tag.to_sym)
end

#get(key) ⇒ Object



18
19
20
21
22
23
# File 'lib/togls/feature_registry.rb', line 18

def get(key)
  @registry.fetch(key) do |key|
    Togls.logger.warn("Feature identified by #{key} has not been defined")
    @default_feature
  end
end