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.
-
#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 = []) ⇒ Feature
constructor
Creates a new instance of an Interval RefreshPolicy.
Constructor Details
#initialize(name, enabled_for = [], disabled_for = []) ⇒ Feature
Creates a new instance of an Interval RefreshPolicy.
19 20 21 22 23 |
# File 'lib/eight_ball/feature.rb', line 19 def initialize(name, enabled_for = [], disabled_for = []) @name = name @enabled_for = Array enabled_for @disabled_for = Array disabled_for 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 |
#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?
51 52 53 54 55 56 57 |
# File 'lib/eight_ball/feature.rb', line 51 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 } } end |
#enabled?(parameters = {}) ⇒ true, false
“EightBall, is this Feature enabled?”
44 45 46 47 48 49 |
# File 'lib/eight_ball/feature.rb', line 44 def enabled?(parameters = {}) 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 |