2013-01-13 16:25:49 -05:00
|
|
|
module Mutant
|
|
|
|
class Subject
|
|
|
|
# Abstract base class for method subjects
|
|
|
|
class Method < self
|
|
|
|
|
|
|
|
# Test if method is public
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if method is public
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :public?
|
|
|
|
|
2013-06-15 10:32:40 -04:00
|
|
|
# Return method name
|
2013-06-14 14:29:36 -04:00
|
|
|
#
|
2013-06-15 10:32:40 -04:00
|
|
|
# @return [Symbol]
|
2013-06-14 14:29:36 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-15 10:32:40 -04:00
|
|
|
def name
|
|
|
|
node.children[self.class::NAME_INDEX]
|
2013-06-14 14:29:36 -04:00
|
|
|
end
|
2013-06-14 14:23:46 -04:00
|
|
|
|
2013-06-15 10:32:40 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
# Return scope
|
2013-01-21 17:54:25 -05:00
|
|
|
#
|
2013-06-15 10:32:40 -04:00
|
|
|
# @return [Class, Module]
|
2013-01-21 17:54:25 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-15 10:32:40 -04:00
|
|
|
def scope
|
|
|
|
context.scope
|
2013-01-21 17:54:25 -05:00
|
|
|
end
|
|
|
|
|
2013-06-14 14:29:36 -04:00
|
|
|
# Return subtype identifier
|
2013-01-21 17:54:25 -05:00
|
|
|
#
|
2013-06-14 14:29:36 -04:00
|
|
|
# @return [String]
|
2013-01-21 17:54:25 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-14 14:29:36 -04:00
|
|
|
def subtype
|
|
|
|
"#{context.identification}#{self.class::SYMBOL}#{name}"
|
2013-01-21 17:54:25 -05:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:25:49 -05:00
|
|
|
# Instance method subjects
|
|
|
|
class Instance < self
|
|
|
|
|
2013-06-14 14:29:36 -04:00
|
|
|
NAME_INDEX = 0
|
|
|
|
SYMBOL = '#'.freeze
|
|
|
|
|
2013-01-13 16:25:49 -05:00
|
|
|
# Test if method is public
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if method is public
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def public?
|
2013-01-21 17:54:25 -05:00
|
|
|
scope.public_method_defined?(name)
|
2013-01-13 16:25:49 -05:00
|
|
|
end
|
|
|
|
memoize :public?
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2013-06-14 14:23:46 -04:00
|
|
|
end # Instance
|
2013-01-13 16:25:49 -05:00
|
|
|
|
|
|
|
# Singleton method subjects
|
2013-04-17 23:31:21 -04:00
|
|
|
class Singleton < self
|
2013-01-13 16:25:49 -05:00
|
|
|
|
2013-06-14 14:29:36 -04:00
|
|
|
NAME_INDEX = 1
|
|
|
|
SYMBOL = '.'.freeze
|
|
|
|
|
2013-01-13 16:25:49 -05:00
|
|
|
# Test if method is public
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if method is public
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def public?
|
2013-01-21 17:54:25 -05:00
|
|
|
scope.singleton_class.public_method_defined?(name)
|
2013-01-13 16:25:49 -05:00
|
|
|
end
|
|
|
|
memoize :public?
|
|
|
|
|
2013-06-14 14:23:46 -04:00
|
|
|
end # Singleton
|
|
|
|
|
|
|
|
end # Method
|
|
|
|
end # Subject
|
|
|
|
end # Mutant
|