Class: Shamu::Features::Conditions::Condition

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

Overview

A condition that must be met for a Selector to match and enable a Toggle.

Direct Known Subclasses

Env, Hosts, Matching, Percentage, Proc, Roles, ScheduleAt

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, toggle) ⇒ Condition

Returns a new instance of Condition.

Parameters:

  • config (Object)

    options selected for the condition.



20
21
22
23
# File 'lib/shamu/features/conditions/condition.rb', line 20

def initialize( config, toggle )
  @config = config
  @toggle = toggle
end

Class Method Details

.create(name, config, toggle) ⇒ Object

Parameters:

  • name (String)

    of the condition.

  • config (Object)

    settings for the condition.



11
12
13
14
15
16
17
# File 'lib/shamu/features/conditions/condition.rb', line 11

def self.create( name, config, toggle )
  @condition_class ||= Hash.new do |hash, key|
    hash[key] = "Shamu::Features::Conditions::#{ key.to_s.camelize }".constantize
  end

  @condition_class[name].new config, toggle
end

Instance Method Details

#match?(context) ⇒ Boolean

Returns true if the condition matches the given environment.

Parameters:

  • context (Context)

    the feature evaluation context.

Returns:

  • (Boolean)

    true if the condition matches the given environment.



27
28
29
# File 'lib/shamu/features/conditions/condition.rb', line 27

def match?( context )
  fail NotImplementedError
end