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