Class: Togls::ToggleRegistry

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

Overview

Toggle Registry

The Toggle Registry conceptually houses a registry of toggles. It accomplishes this by interfacing with the provided feature repository, and toggle repository. This plays a significant portion in the primary DSL as well.

Instance Method Summary collapse

Constructor Details

#initialize(feature_repository, toggle_repository) ⇒ ToggleRegistry

Returns a new instance of ToggleRegistry.



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

def initialize(feature_repository, toggle_repository)
  @feature_repository = feature_repository
  @toggle_repository = toggle_repository
end

Instance Method Details

#expand(&block) ⇒ Object



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

def expand(&block)
  instance_eval(&block)
  self
end

#feature(key, desc, target_type: Togls.default_feature_target_type) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/togls/toggle_registry.rb', line 19

def feature(key, desc, target_type: Togls.default_feature_target_type)
  verify_uniqueness_of_feature(key)
  feature = Togls::Feature.new(key, desc, target_type)
  toggle = Togls::Toggle.new(feature)
  @toggle_repository.store(toggle)
  Togls::Toggler.new(@toggle_repository, toggle)
end

#get(key) ⇒ Object



33
34
35
# File 'lib/togls/toggle_registry.rb', line 33

def get(key)
  @toggle_repository.get(key.to_s)
end

#verify_uniqueness_of_feature(key) ⇒ Object



27
28
29
30
31
# File 'lib/togls/toggle_registry.rb', line 27

def verify_uniqueness_of_feature(key)
  if @feature_repository.include?(key.to_s)
    raise FeatureAlreadyDefined, "Feature identified by '#{key}' has already been defined"
  end
end