2012-07-23 16:54:35 -04:00
|
|
|
module Mutant
|
2012-07-30 22:10:37 -04:00
|
|
|
class Matcher
|
2012-08-09 17:07:22 -04:00
|
|
|
class Method < self
|
2012-07-26 13:25:23 -04:00
|
|
|
# Matcher for instance methods
|
2012-08-09 17:07:22 -04:00
|
|
|
class Instance < self
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Extract instance method matchers from scope
|
|
|
|
#
|
|
|
|
# @param [Class|Module] scope
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Matcher::Method::Instance>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.each(scope)
|
|
|
|
return to_enum unless block_given?
|
|
|
|
return unless scope.kind_of?(Module)
|
|
|
|
scope.public_instance_methods(false).map do |name|
|
|
|
|
yield new(scope, name)
|
2012-08-14 16:45:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def identification
|
|
|
|
"#{scope.name}##{method_name}"
|
|
|
|
end
|
2012-08-16 13:10:24 -04:00
|
|
|
|
2012-07-23 16:54:35 -04:00
|
|
|
private
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2012-08-16 13:10:24 -04:00
|
|
|
# Check if node is matched
|
2012-07-30 22:10:37 -04:00
|
|
|
#
|
2012-08-16 13:10:24 -04:00
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true if node matches method
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# returns false if node NOT matches method
|
2012-07-23 19:41:08 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 13:10:24 -04:00
|
|
|
def match?(node)
|
|
|
|
node.line == source_line &&
|
|
|
|
node.class == Rubinius::AST::Define &&
|
|
|
|
node.name == method_name
|
2012-07-23 16:54:35 -04:00
|
|
|
end
|
|
|
|
|
2012-08-16 13:10:24 -04:00
|
|
|
# Return method instance
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-08-16 13:10:24 -04:00
|
|
|
# @return [UnboundMethod]
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 13:10:24 -04:00
|
|
|
def method
|
|
|
|
scope.instance_method(method_name)
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
2012-08-16 13:10:24 -04:00
|
|
|
|
2012-07-23 16:54:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|