Class: Shamu::Features::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/shamu/features/selector.rb

Overview

A selector used to match conditions against environment configuration.

Attributes collapse

Instance Method Summary collapse

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

#conditionsArray<Condition>

Returns conditions that must match for the selector to match.

Returns:

  • (Array<Condition>)

    conditions that must match for the selector to match.



14
15
16
# File 'lib/shamu/features/selector.rb', line 14

def conditions
  @conditions
end

#rejectBoolean

Returns true if the feature should not be enabled when the selector matches.

Returns:

  • (Boolean)

    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

#toggleToggle

Returns that owns the selector.

Returns:

  • (Toggle)

    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.

Parameters:

  • context (Context)

    the feature evaluation context.

Returns:

  • (Boolean)

    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