Class: Mutant::Matcher::Builder

Inherits:
Object
  • Object
show all
Includes:
AST::Sexp
Defined in:
lib/mutant/matcher/builder.rb

Overview

Builder for complex matchers

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initalize object

Parameters:



15
16
17
18
19
20
# File 'lib/mutant/matcher/builder.rb', line 15

def initialize(env)
  super
  @matchers          = []
  @subject_ignores   = []
  @subject_selectors = []
end

Instance Method Details

#add_match_expression(expression) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add a match expression

Parameters:

Returns:

  • (self)


56
57
58
59
# File 'lib/mutant/matcher/builder.rb', line 56

def add_match_expression(expression)
  @matchers << expression.matcher(env)
  self
end

#add_subject_ignore(expression) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add a subject ignore

Parameters:

Returns:

  • (self)


30
31
32
33
# File 'lib/mutant/matcher/builder.rb', line 30

def add_subject_ignore(expression)
  @subject_ignores << expression.matcher(env)
  self
end

#add_subject_selector(attribute, value) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add a subject selector

Parameters:

  • selector (#call)

Returns:

  • (self)


43
44
45
46
# File 'lib/mutant/matcher/builder.rb', line 43

def add_subject_selector(attribute, value)
  @subject_selectors << Morpher.compile(s(:eql, s(:attribute, attribute), s(:static, value)))
  self
end

#matcherMutant::Matcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return generated matcher

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mutant/matcher/builder.rb', line 67

def matcher
  if @matchers.empty?
    return Matcher::Null.new
  end

  matcher = Matcher::Chain.build(@matchers)

  if predicate
    Matcher::Filter.new(matcher, predicate)
  else
    matcher
  end
end