2012-09-10 19:00:18 -04:00
|
|
|
module Mutant
|
|
|
|
class Matcher
|
2013-04-20 15:16:48 -04:00
|
|
|
|
2013-01-21 14:08:30 -05:00
|
|
|
# Matcher for specific namespace
|
2014-06-26 16:57:14 -04:00
|
|
|
#
|
|
|
|
# rubocop:disable LineLength
|
2013-01-21 14:08:30 -05:00
|
|
|
class Namespace < self
|
2014-06-30 09:06:57 -04:00
|
|
|
include Concord::Public.new(:env, :expression)
|
2013-04-19 17:36:49 -04:00
|
|
|
|
2012-09-10 19:00:18 -04:00
|
|
|
# Enumerate subjects
|
|
|
|
#
|
|
|
|
# @return [self]
|
2013-01-21 14:08:30 -05:00
|
|
|
# if block given
|
|
|
|
#
|
|
|
|
# @return [Enumerator<Subject>]
|
|
|
|
# otherwise
|
2012-09-10 19:00:18 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def each(&block)
|
|
|
|
return to_enum unless block_given?
|
2014-07-02 13:47:51 -04:00
|
|
|
|
|
|
|
env.matchable_scopes.select do |scope|
|
|
|
|
scope.each(&block) if match?(scope)
|
2012-09-10 19:00:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-06-30 08:06:51 -04:00
|
|
|
# Test scope if name matches expresion
|
2012-09-10 19:00:18 -04:00
|
|
|
#
|
2014-07-02 13:47:51 -04:00
|
|
|
# @param [Module, Class] scope
|
2012-09-10 19:00:18 -04:00
|
|
|
#
|
2014-06-30 08:06:51 -04:00
|
|
|
# @return [Boolean]
|
2012-09-10 19:00:18 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-06-30 08:06:51 -04:00
|
|
|
def match?(scope)
|
2014-07-02 13:47:51 -04:00
|
|
|
expression.prefix?(scope.expression)
|
2012-09-10 19:00:18 -04:00
|
|
|
end
|
2013-04-20 15:16:48 -04:00
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Namespace
|
|
|
|
end # Matcher
|
|
|
|
end # Mutant
|