Class: Flipflop::Strategies::AbstractStrategy
- Inherits:
-
Object
- Object
- Flipflop::Strategies::AbstractStrategy
- Defined in:
- lib/flipflop/strategies/abstract_strategy.rb
Direct Known Subclasses
ActiveRecordStrategy, CookieStrategy, DefaultStrategy, LambdaStrategy, QueryStringStrategy, RedisStrategy, SequelStrategy, SessionStrategy, TestStrategy
Defined Under Namespace
Modules: RequestInterceptor
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#clear!(feature) ⇒ Object
Remove the feature symbol from this strategy.
-
#enabled?(feature) ⇒ Boolean
Return true iff the given feature symbol is explicitly enabled.
- #hidden? ⇒ Boolean
-
#initialize(**options) ⇒ AbstractStrategy
constructor
A new instance of AbstractStrategy.
-
#reset! ⇒ Object
Optional.
-
#switch!(feature, enabled) ⇒ Object
Enable/disable (true/false) the given feature symbol explicitly.
-
#switchable? ⇒ Boolean
Return true iff this strategy is able to switch features on/off.
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(**) # Generate key before setting instance that should be excluded from # unique key generation. @key = OptionsHasher.new(self).generate @name = (.delete(:name) || self.class.default_name).freeze @title = @name.humanize.freeze @description = (.delete(:description) || self.class.default_description).freeze @hidden = !!.delete(:hidden) || false if .any? raise StrategyError.new(name, "did not understand option #{.keys.map(&:inspect) * ', '}") end end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
38 39 40 |
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38 def description @description end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
38 39 40 |
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 38 def name @name end |
#title ⇒ Object (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_description ⇒ Object
34 35 |
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 34 def default_description end |
.default_name ⇒ Object
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.
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.
68 69 70 |
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 68 def enabled?(feature) raise NotImplementedError end |
#hidden? ⇒ 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.
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.
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.
61 62 63 |
# File 'lib/flipflop/strategies/abstract_strategy.rb', line 61 def switchable? false end |