Class: Togls::FeatureRepository
- Inherits:
-
Object
- Object
- Togls::FeatureRepository
- Defined in:
- lib/togls/feature_repository.rb
Instance Method Summary collapse
- #extract_feature_data(feature) ⇒ Object
- #fetch_feature_data(id) ⇒ Object
- #get(feature_id) ⇒ Object
-
#initialize(drivers) ⇒ FeatureRepository
constructor
A new instance of FeatureRepository.
- #reconstitute_feature(feature_data) ⇒ Object
- #store(feature) ⇒ Object
Constructor Details
#initialize(drivers) ⇒ FeatureRepository
Returns a new instance of FeatureRepository.
3 4 5 6 7 8 9 10 11 |
# File 'lib/togls/feature_repository.rb', line 3 def initialize(drivers) if !drivers.is_a?(Array) raise Togls::InvalidDriver.new("FeatureRepository requires a valid driver") end if drivers.empty? raise Togls::MissingDriver.new("FeatureRepository requires a driver") end @drivers = drivers end |
Instance Method Details
#extract_feature_data(feature) ⇒ Object
20 21 22 |
# File 'lib/togls/feature_repository.rb', line 20 def extract_feature_data(feature) { "key" => feature.key, "description" => feature.description } end |
#fetch_feature_data(id) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/togls/feature_repository.rb', line 24 def fetch_feature_data(id) feature_data = nil @drivers.reverse.each do |driver| feature_data = driver.get(id) break if feature_data end feature_data end |
#get(feature_id) ⇒ Object
33 34 35 36 |
# File 'lib/togls/feature_repository.rb', line 33 def get(feature_id) feature_data = fetch_feature_data(feature_id) reconstitute_feature(feature_data) end |
#reconstitute_feature(feature_data) ⇒ Object
38 39 40 41 |
# File 'lib/togls/feature_repository.rb', line 38 def reconstitute_feature(feature_data) Togls::Feature.new(feature_data["key"], feature_data["description"]) end |
#store(feature) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/togls/feature_repository.rb', line 13 def store(feature) feature_data = extract_feature_data(feature) @drivers.each do |driver| driver.store(feature.id, feature_data) end end |