Class: Unleash::Strategies
- Inherits:
-
Object
- Object
- Unleash::Strategies
- Defined in:
- lib/unleash/strategies.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, strategy) ⇒ Object
- #add(strategy) ⇒ Object
- #fetch(name) ⇒ Object
- #includes?(name) ⇒ Boolean
-
#initialize ⇒ Strategies
constructor
A new instance of Strategies.
- #keys ⇒ Object
- #register_strategies ⇒ Object
Constructor Details
#initialize ⇒ Strategies
Returns a new instance of Strategies.
6 7 8 9 |
# File 'lib/unleash/strategies.rb', line 6 def initialize @strategies = {} register_strategies end |
Instance Method Details
#[](key) ⇒ Object
34 35 36 |
# File 'lib/unleash/strategies.rb', line 34 def [](key) @strategies[key.to_s] end |
#[]=(key, strategy) ⇒ Object
29 30 31 32 |
# File 'lib/unleash/strategies.rb', line 29 def []=(key, strategy) warn_deprecated_registration(strategy, 'modifying Unleash::STRATEGIES') @strategies[key.to_s] = strategy end |
#add(strategy) ⇒ Object
25 26 27 |
# File 'lib/unleash/strategies.rb', line 25 def add(strategy) @strategies[strategy.name] = strategy end |
#fetch(name) ⇒ Object
19 20 21 22 23 |
# File 'lib/unleash/strategies.rb', line 19 def fetch(name) raise Unleash::Strategy::NotImplemented, "Strategy is not implemented" unless (strategy = @strategies[name.to_s]) strategy end |
#includes?(name) ⇒ Boolean
15 16 17 |
# File 'lib/unleash/strategies.rb', line 15 def includes?(name) @strategies.has_key?(name.to_s) end |
#keys ⇒ Object
11 12 13 |
# File 'lib/unleash/strategies.rb', line 11 def keys @strategies.keys end |
#register_strategies ⇒ Object
38 39 40 41 |
# File 'lib/unleash/strategies.rb', line 38 def register_strategies register_base_strategies register_custom_strategies end |