Class: Flipflop::Strategies::AbstractStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/flipflop/strategies/abstract_strategy.rb

Defined Under Namespace

Modules: RequestInterceptor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ AbstractStrategy

Returns a new instance of AbstractStrategy.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 40

def initialize(**options)
  # Generate key before setting instance that should be excluded from
  # unique key generation.
  @key = OptionsHasher.new(self).generate

  @name = (options.delete(:name) || self.class.default_name).freeze
  @title = @name.humanize.freeze
  @description = (options.delete(:description) || self.class.default_description).freeze
  @hidden = !!options.delete(:hidden) || false

  if options.any?
    raise StrategyError.new(name, "did not understand option #{options.keys.map(&:inspect) * ', '}")
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



38
39
40
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38

def description
  @description
end

#keyObject (readonly)

Returns the value of attribute key.



38
39
40
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38

def name
  @name
end

#titleObject (readonly)

Returns the value of attribute title.



38
39
40
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38

def title
  @title
end

Class Method Details

.default_descriptionObject



34
35
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 34

def default_description
end

.default_nameObject



29
30
31
32
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 29

def default_name
  return "anonymous" unless name
  name.split("::").last.gsub(/Strategy$/, "").underscore
end

Instance Method Details

#clear!(feature) ⇒ Object

Remove the feature symbol from this strategy. It should no longer be recognized afterwards: enabled?(feature) will return nil.

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 79

def clear!(feature)
  raise NotImplementedError
end

#enabled?(feature) ⇒ Boolean

Return true iff the given feature symbol is explicitly enabled. Return false iff the given feature symbol is explicitly disabled. Return nil iff the given feature symbol is unknown by this strategy.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 68

def enabled?(feature)
  raise NotImplementedError
end

#hidden?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 55

def hidden?
  @hidden
end

#reset!Object

Optional. Remove all features, so that no feature is known.

Raises:

  • (NotImplementedError)


84
85
86
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 84

def reset!
  raise NotImplementedError
end

#switch!(feature, enabled) ⇒ Object

Enable/disable (true/false) the given feature symbol explicitly.

Raises:

  • (NotImplementedError)


73
74
75
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 73

def switch!(feature, enabled)
  raise NotImplementedError
end

#switchable?Boolean

Return true iff this strategy is able to switch features on/off. Return false otherwise.

Returns:

  • (Boolean)


61
62
63
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 61

def switchable?
  false
end