free_mutant/lib/mutant/matcher/namespace.rb

47 lines
874 B
Ruby
Raw Normal View History

module Mutant
class Matcher
# Matcher for specific namespace
#
# rubocop:disable LineLength
class Namespace < self
include Concord::Public.new(:env, :expression)
2013-04-19 17:36:49 -04:00
# Enumerate subjects
#
# @return [self]
# if block given
#
# @return [Enumerator<Subject>]
# otherwise
#
# @api private
#
def each(&block)
return to_enum unless block_given?
env.matchable_scopes.select do |scope|
scope.each(&block) if match?(scope)
end
self
end
private
# Test scope if name matches expresion
#
# @param [Module, Class] scope
#
# @return [Boolean]
#
# @api private
#
def match?(scope)
expression.prefix?(scope.expression)
end
2013-06-14 14:54:02 -04:00
end # Namespace
end # Matcher
end # Mutant