Class: EightBall::Feature
- Inherits:
-
Object
- Object
- EightBall::Feature
- Defined in:
- lib/eight_ball/feature.rb
Overview
A Feature is an element of your application that can be enabled or disabled based on various Conditions.
Instance Attribute Summary collapse
-
#disabled_for ⇒ Object
readonly
Returns the value of attribute disabled_for.
-
#enabled_for ⇒ Object
readonly
Returns the value of attribute enabled_for.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#enabled?(parameters = {}) ⇒ true, false
"EightBall, is this Feature enabled?".
-
#initialize(name, enabled_for = [], disabled_for = [], metadata: nil) ⇒ Feature
constructor
Creates a new instance of an Interval RefreshPolicy.
-
#un_evaluable! ⇒ nil
Marks this Feature un-evaluable: #enabled? always returns
falseand its Conditions are never inspected. -
#un_evaluable? ⇒ Boolean
Whether this Feature has been marked un-evaluable.
Constructor Details
#initialize(name, enabled_for = [], disabled_for = [], metadata: nil) ⇒ Feature
Creates a new instance of an Interval RefreshPolicy.
21 22 23 24 25 26 27 |
# File 'lib/eight_ball/feature.rb', line 21 def initialize(name, enabled_for = [], disabled_for = [], metadata: nil) @name = name @enabled_for = inject_flag_name(Array(enabled_for)) @disabled_for = inject_flag_name(Array(disabled_for)) @metadata = @un_evaluable = false end |
Instance Attribute Details
#disabled_for ⇒ Object (readonly)
Returns the value of attribute disabled_for.
7 8 9 |
# File 'lib/eight_ball/feature.rb', line 7 def disabled_for @disabled_for end |
#enabled_for ⇒ Object (readonly)
Returns the value of attribute enabled_for.
7 8 9 |
# File 'lib/eight_ball/feature.rb', line 7 def enabled_for @enabled_for end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/eight_ball/feature.rb', line 7 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/eight_ball/feature.rb', line 7 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
71 72 73 74 75 76 77 78 |
# File 'lib/eight_ball/feature.rb', line 71 def ==(other) name == other.name && enabled_for.size == other.enabled_for.size && enabled_for.all? { |condition| other.enabled_for.any? { |other_condition| condition == other_condition } } && disabled_for.size == other.disabled_for.size && disabled_for.all? { |condition| other.disabled_for.any? { |other_condition| condition == other_condition } } && == other. end |
#enabled?(parameters = {}) ⇒ true, false
"EightBall, is this Feature enabled?"
48 49 50 51 52 53 54 55 |
# File 'lib/eight_ball/feature.rb', line 48 def enabled?(parameters = {}) return false if @un_evaluable return true if @enabled_for.empty? && @disabled_for.empty? return true if @enabled_for.empty? && !any_satisfied?(@disabled_for, parameters) any_satisfied?(@enabled_for, parameters) && !any_satisfied?(@disabled_for, parameters) end |
#un_evaluable! ⇒ nil
Marks this Feature un-evaluable: #enabled? always returns false and its
Conditions are never inspected. Used by Marshallers to fail a bad flag closed.
61 62 63 64 |
# File 'lib/eight_ball/feature.rb', line 61 def un_evaluable! @un_evaluable = true nil end |
#un_evaluable? ⇒ Boolean
Returns whether this Feature has been marked un-evaluable.
67 68 69 |
# File 'lib/eight_ball/feature.rb', line 67 def un_evaluable? @un_evaluable end |