Class: Shamu::Features::Selector
- Inherits:
-
Object
- Object
- Shamu::Features::Selector
- Defined in:
- lib/shamu/features/selector.rb
Overview
A selector used to match conditions against environment configuration.
Attributes collapse
-
#conditions ⇒ Array<Condition>
Conditions that must match for the selector to match.
-
#reject ⇒ Boolean
True if the feature should not be enabled when the selector matches.
-
#toggle ⇒ Toggle
That owns the selector.
Instance Method Summary collapse
-
#initialize(toggle, config) ⇒ Selector
constructor
A new instance of Selector.
-
#match?(context) ⇒ Boolean
True if the selector matches the given environment.
Constructor Details
#initialize(toggle, config) ⇒ Selector
Returns a new instance of Selector.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/shamu/features/selector.rb', line 28 def initialize( toggle, config ) @conditions = [] config.each do |name, condition_config| if name == "reject" @reject = condition_config.to_bool else @conditions << Conditions::Condition.create( name, condition_config, toggle ) end end @conditions.freeze end |
Instance Attribute Details
#conditions ⇒ Array<Condition>
Returns conditions that must match for the selector to match.
14 15 16 |
# File 'lib/shamu/features/selector.rb', line 14 def conditions @conditions end |
#reject ⇒ Boolean
Returns true if the feature should not be enabled when the selector matches.
19 20 21 |
# File 'lib/shamu/features/selector.rb', line 19 def reject @reject end |
#toggle ⇒ Toggle
Returns that owns the selector.
23 24 25 |
# File 'lib/shamu/features/selector.rb', line 23 def toggle @toggle end |
Instance Method Details
#match?(context) ⇒ Boolean
Returns true if the selector matches the given environment.
44 45 46 |
# File 'lib/shamu/features/selector.rb', line 44 def match?( context ) conditions.all? { |c| c.match?( context ) } end |