Add scope classifier and matcher
This simplifies the namespace matcher a lot, it can use the scope matcher internally.
This commit is contained in:
parent
15376e6314
commit
3965ca4eae
4 changed files with 74 additions and 20 deletions
|
@ -97,6 +97,7 @@ require 'mutant/matcher/method/singleton'
|
|||
require 'mutant/matcher/method/instance'
|
||||
require 'mutant/matcher/methods'
|
||||
require 'mutant/matcher/namespace'
|
||||
require 'mutant/matcher/scope'
|
||||
require 'mutant/killer'
|
||||
require 'mutant/killer/static'
|
||||
require 'mutant/killer/rspec'
|
||||
|
@ -118,6 +119,7 @@ require 'mutant/cli'
|
|||
require 'mutant/cli/classifier'
|
||||
require 'mutant/cli/classifier/namespace'
|
||||
require 'mutant/cli/classifier/method'
|
||||
require 'mutant/cli/classifier/scope'
|
||||
require 'mutant/color'
|
||||
require 'mutant/differ'
|
||||
require 'mutant/reporter'
|
||||
|
|
35
lib/mutant/cli/classifier/scope.rb
Normal file
35
lib/mutant/cli/classifier/scope.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Mutant
|
||||
class CLI
|
||||
class Classifier
|
||||
|
||||
# Scope classifier
|
||||
class Scope < self
|
||||
|
||||
REGEXP = %r(\A(#{SCOPE_PATTERN})\z).freeze
|
||||
|
||||
private
|
||||
|
||||
# Return matcher
|
||||
#
|
||||
# @return [Matcher]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def matcher
|
||||
Matcher::Scope.new(scope)
|
||||
end
|
||||
|
||||
# Return namespace
|
||||
#
|
||||
# @return [Class, Module]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def scope
|
||||
Classifier.constant_lookup(match[1].to_s)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +1,10 @@
|
|||
module Mutant
|
||||
class Matcher
|
||||
|
||||
# Matcher for specific namespace
|
||||
class Namespace < self
|
||||
include Concord.new(:namespace)
|
||||
|
||||
MATCHERS = [
|
||||
Matcher::Methods::Singleton,
|
||||
Matcher::Methods::Instance
|
||||
].freeze
|
||||
|
||||
# Enumerate subjects
|
||||
#
|
||||
# @return [self]
|
||||
|
@ -23,7 +19,7 @@ module Mutant
|
|||
return to_enum unless block_given?
|
||||
|
||||
scopes.each do |scope|
|
||||
emit_scope_matches(scope, &block)
|
||||
Scope.each(scope, &block)
|
||||
end
|
||||
|
||||
self
|
||||
|
@ -42,20 +38,6 @@ module Mutant
|
|||
end
|
||||
memoize :pattern
|
||||
|
||||
# Yield matchers for scope
|
||||
#
|
||||
# @param [Class,Module] scope
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_scope_matches(scope, &block)
|
||||
MATCHERS.each do |matcher|
|
||||
matcher.each(scope, &block)
|
||||
end
|
||||
end
|
||||
|
||||
# Return scope enumerator
|
||||
#
|
||||
# @return [Enumerable<Object>]
|
||||
|
@ -83,6 +65,7 @@ module Mutant
|
|||
yield scope
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
34
lib/mutant/matcher/scope.rb
Normal file
34
lib/mutant/matcher/scope.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Mutant
|
||||
class Matcher
|
||||
# Matcher for specific namespace
|
||||
class Scope < self
|
||||
include Concord.new(:scope)
|
||||
|
||||
MATCHERS = [
|
||||
Matcher::Methods::Singleton,
|
||||
Matcher::Methods::Instance
|
||||
].freeze
|
||||
|
||||
# Enumerate subjects
|
||||
#
|
||||
# @return [self]
|
||||
# if block given
|
||||
#
|
||||
# @return [Enumerator<Subject>]
|
||||
# otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def each(&block)
|
||||
return to_enum unless block_given?
|
||||
|
||||
MATCHERS.each do |matcher|
|
||||
matcher.each(scope, &block)
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue