Class: Dolphin::FeatureStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dolphin/feature_store.rb

Overview

Encapsulates a mapping from feature name -> flipper name, stored in a YAML file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_file) ⇒ FeatureStore


5
6
7
8
# File 'lib/dolphin/feature_store.rb', line 5

def initialize(feature_file)
  @feature_file = File.expand_path(feature_file)
  @features     = read_file
end

Instance Attribute Details

#feature_fileObject (readonly)

Returns the value of attribute feature_file


10
11
12
# File 'lib/dolphin/feature_store.rb', line 10

def feature_file
  @feature_file
end

Instance Method Details

#[](feature_name) ⇒ Object


12
13
14
# File 'lib/dolphin/feature_store.rb', line 12

def [](feature_name)
  features[feature_name.to_s]
end

#clearObject


38
39
40
41
# File 'lib/dolphin/feature_store.rb', line 38

def clear
  @last_read = @features = nil
  save({})
end

#delete_feature(feature) ⇒ Object


31
32
33
34
35
36
# File 'lib/dolphin/feature_store.rb', line 31

def delete_feature(feature)
  stored_features = features
  stored_features.delete(feature.to_s)

  save(stored_features)
end

#featuresObject


16
17
18
19
20
21
22
# File 'lib/dolphin/feature_store.rb', line 16

def features
  unless file_updated?
    return @features
  end
  
  @features = read_file
end

#update_feature(feature, flipper) ⇒ Object


24
25
26
27
28
29
# File 'lib/dolphin/feature_store.rb', line 24

def update_feature(feature, flipper)
  stored_features               = features
  stored_features[feature.to_s] = flipper.to_s

  save(stored_features)
end