Sha256: d28770113f34f81eeb5ccf826622579cbe4cc76453ac6d0896e47a739200f1b3

Contents?: true

Size: 845 Bytes

Versions: 13

Compression:

Stored size: 845 Bytes

Contents

module Unleash
  class DefaultOverrideError < RuntimeError
  end

  class Strategies
    attr_accessor :strategies

    def initialize
      @strategies = {}
    end

    def includes?(name)
      @strategies.has_key?(name.to_s) || DEFAULT_STRATEGIES.include?(name.to_s)
    end

    def add(strategy)
      raise DefaultOverrideError, "Cannot override a default strategy" if DEFAULT_STRATEGIES.include?(strategy.name)

      @strategies[strategy.name] = strategy
    end

    def custom_strategies
      @strategies.values
    end

    def known_strategies
      @strategies.keys.map{ |key| { name: key } }
    end

    DEFAULT_STRATEGIES = ['applicationHostname', 'default', 'flexibleRollout', 'gradualRolloutRandom', 'gradualRolloutSessionId',
                          'gradualRolloutUserId', 'remoteAddress', 'userWithId'].freeze
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
unleash-6.0.9 lib/unleash/strategies.rb
unleash-6.0.8 lib/unleash/strategies.rb
unleash-6.0.8.beta.1 lib/unleash/strategies.rb
unleash-6.0.7 lib/unleash/strategies.rb
unleash-6.0.6 lib/unleash/strategies.rb
unleash-6.0.5 lib/unleash/strategies.rb
unleash-6.0.0 lib/unleash/strategies.rb
unleash-6.0.5.pre lib/unleash/strategies.rb
unleash-6.0.4.pre lib/unleash/strategies.rb
unleash-6.0.3.pre lib/unleash/strategies.rb
unleash-6.0.2.pre lib/unleash/strategies.rb
unleash-6.0.1.pre lib/unleash/strategies.rb
unleash-6.0.0.pre lib/unleash/strategies.rb