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



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>



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

def conditions
  @conditions
end

#rejectBoolean



19
20
21
# File 'lib/shamu/features/selector.rb', line 19

def reject
  @reject
end

#toggleToggle



23
24
25
# File 'lib/shamu/features/selector.rb', line 23

def toggle
  @toggle
end

Instance Method Details

#match?(context) ⇒ Boolean



44
45
46
# File 'lib/shamu/features/selector.rb', line 44

def match?( context )
  conditions.all? { |c| c.match?( context ) }
end