free_mutant/lib/mutant/matcher/chain.rb
Dan Kubb 7293386c26 Add magic encoding header to all ruby files
* rubocop still warns about this on ruby 1.9.3, so it was fixed so
  it produces less output on travis.
2013-07-28 16:03:06 -07:00

47 lines
882 B
Ruby

# encoding: utf-8
module Mutant
class Matcher
# A chain of matchers
class Chain < self
include Concord::Public.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?
matchers.each do |matcher|
matcher.each(&block)
end
self
end
# 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
end # Chain
end # Matcher
end # Mutant