lib/unleash/strategies.rb in unleash-5.0.4 vs lib/unleash/strategies.rb in unleash-5.0.5
- old
+ new
@@ -21,11 +21,15 @@
strategy
end
def add(strategy)
- @strategies[strategy.name] = strategy
+ if default_strategy_names.include?(strategy.name)
+ Unleash.logger.error "WARNING: Overriding built in strategy '#{strategy.name}'. OVERIDING BUILT IN STRATEGIES IS \
+DEPRECATED AND WILL BE REMOVED IN A FUTURE RELEASE."
+ end
+ self.internal_add(strategy)
end
def []=(key, strategy)
warn_deprecated_registration(strategy, 'modifying Unleash::STRATEGIES')
@strategies[key.to_s] = strategy
@@ -50,15 +54,23 @@
.map{ |c| Object.const_get("Unleash::Strategy::#{c}") }
.reject{ |c| DEFAULT_STRATEGIES.include?(c) } # Reject base classes
.each do |c|
strategy = c.new
warn_deprecated_registration(strategy, 'adding custom class into Unleash::Strategy namespace')
- self.add(strategy)
+ self.internal_add(strategy)
end
end
def register_base_strategies
- DEFAULT_STRATEGIES.each{ |c| self.add(c.new) }
+ DEFAULT_STRATEGIES.each{ |c| self.internal_add(c.new) }
+ end
+
+ def internal_add(strategy)
+ @strategies[strategy.name] = strategy
+ end
+
+ def default_strategy_names
+ DEFAULT_STRATEGIES.map{ |strategy_class| strategy_class.new.name }
end
DEFAULT_STRATEGIES = [
Unleash::Strategy::ApplicationHostname,
Unleash::Strategy::Default,