2012-08-29 08:00:37 -04:00
|
|
|
module Mutant
|
|
|
|
class Matcher
|
|
|
|
# A chain of matchers
|
|
|
|
class Chain < self
|
|
|
|
include Equalizer.new(:matchers)
|
|
|
|
|
|
|
|
# Enumerate subjects
|
|
|
|
#
|
|
|
|
# @return [Enumerator<Subject]
|
|
|
|
# returns subject enumerator if no block given
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
# returnns self otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def each(&block)
|
|
|
|
return to_enum unless block_given?
|
|
|
|
|
2012-10-26 05:24:29 -04:00
|
|
|
matchers.each do |matcher|
|
2012-08-29 08:00:37 -04:00
|
|
|
matcher.each(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return the chain of matchers
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Chain>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
attr_reader :matchers
|
2012-08-29 08:00:37 -04:00
|
|
|
|
2012-11-21 16:28:08 -05:00
|
|
|
# Build matcher chain
|
|
|
|
#
|
|
|
|
# @param [Enumerable<Matcher>] matchers
|
|
|
|
#
|
|
|
|
# @return [Matcher]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.build(matchers)
|
|
|
|
if matchers.length == 1
|
|
|
|
return matchers.first
|
|
|
|
end
|
|
|
|
|
|
|
|
new(matchers)
|
|
|
|
end
|
|
|
|
|
2012-08-29 08:00:37 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
# Initialize chain matcher
|
|
|
|
#
|
|
|
|
# @param [Enumerable<Matcher>] matchers
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(matchers)
|
|
|
|
@matchers = matchers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|