2014-05-30 21:02:15 -04:00
|
|
|
module Mutant
|
|
|
|
class Expression
|
|
|
|
|
|
|
|
# Explicit method expression
|
|
|
|
class Method < self
|
|
|
|
|
|
|
|
MATCHERS = {
|
|
|
|
'.' => Matcher::Methods::Singleton,
|
|
|
|
'#' => Matcher::Methods::Instance
|
|
|
|
}.freeze
|
|
|
|
|
2014-06-08 14:12:16 -04:00
|
|
|
register(
|
|
|
|
/\A(?<scope_name>#{SCOPE_PATTERN})(?<scope_symbol>[.#])(?<method_name>#{METHOD_NAME_PATTERN})\z/
|
|
|
|
)
|
2014-05-30 21:02:15 -04:00
|
|
|
|
|
|
|
# Return method matcher
|
|
|
|
#
|
|
|
|
# @param [Cache] cache
|
|
|
|
#
|
|
|
|
# @return [Matcher::Method]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def matcher(cache)
|
|
|
|
methods_matcher = MATCHERS.fetch(scope_symbol).new(cache, scope)
|
2014-06-02 08:57:14 -04:00
|
|
|
method = methods_matcher.methods.detect do |meth|
|
2014-06-16 06:50:32 -04:00
|
|
|
meth.name.equal?(method_name)
|
2014-05-30 21:02:15 -04:00
|
|
|
end or raise NameError, "Cannot find method #{identifier}"
|
|
|
|
methods_matcher.matcher.build(cache, scope, method)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Return scope name
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def scope_name
|
|
|
|
match[__method__]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return scope
|
|
|
|
#
|
|
|
|
# @return [Class, Method]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def scope
|
|
|
|
Mutant.constant_lookup(scope_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return method name
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def method_name
|
|
|
|
match[__method__].to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return scope symbol
|
|
|
|
#
|
|
|
|
# @return [Symbol]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def scope_symbol
|
|
|
|
match[__method__]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return matcher class
|
|
|
|
#
|
|
|
|
# @return [Class:Mutant::Matcher]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def methods_matcher(cache)
|
|
|
|
MATCHERS.fetch(scope_symbol).new(cache, scope)
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Method
|
|
|
|
end # Expression
|
|
|
|
end # Mutant
|