Class: Trebuchet::Backend::Memory
- Inherits:
-
Object
- Object
- Trebuchet::Backend::Memory
- Defined in:
- lib/trebuchet/backend/memory.rb
Instance Method Summary collapse
- #append_strategy(feature, strategy, options = nil) ⇒ Object
- #get_archived_feature_names ⇒ Object
- #get_feature_names ⇒ Object
- #get_strategy(feature_name) ⇒ Object
-
#initialize(*args) ⇒ Memory
constructor
A new instance of Memory.
- #remove_feature(feature) ⇒ Object
- #remove_strategy(feature) ⇒ Object
- #set_strategy(feature, strategy, options = nil) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Memory
Returns a new instance of Memory.
3 4 5 6 |
# File 'lib/trebuchet/backend/memory.rb', line 3 def initialize(*args) @hash = {} @archived = [] end |
Instance Method Details
#append_strategy(feature, strategy, options = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trebuchet/backend/memory.rb', line 17 def append_strategy(feature, strategy, = nil) @archived.delete(feature) strategies = get_strategy(feature) || [] if i = strategies.index(strategy) strategies.delete_at(i) # remove strategy_name strategies.delete_at(i) # remove options end strategies += [strategy, ] @hash.store(feature, strategies) end |
#get_archived_feature_names ⇒ Object
42 43 44 |
# File 'lib/trebuchet/backend/memory.rb', line 42 def get_archived_feature_names @archived end |
#get_feature_names ⇒ Object
32 33 34 |
# File 'lib/trebuchet/backend/memory.rb', line 32 def get_feature_names @hash.keys end |
#get_strategy(feature_name) ⇒ Object
8 9 10 |
# File 'lib/trebuchet/backend/memory.rb', line 8 def get_strategy(feature_name) @hash.fetch(feature_name, nil) || [] end |
#remove_feature(feature) ⇒ Object
36 37 38 39 40 |
# File 'lib/trebuchet/backend/memory.rb', line 36 def remove_feature(feature) @hash.delete(feature) @archived << feature @archived.uniq! end |
#remove_strategy(feature) ⇒ Object
28 29 30 |
# File 'lib/trebuchet/backend/memory.rb', line 28 def remove_strategy(feature) @hash.delete(feature) end |
#set_strategy(feature, strategy, options = nil) ⇒ Object
12 13 14 15 |
# File 'lib/trebuchet/backend/memory.rb', line 12 def set_strategy(feature, strategy, = nil) @archived.delete(feature) @hash.store(feature, [strategy, ]) end |