7ae6e09908
Strategy currently does not need to be initialized with config.
100 lines
1.8 KiB
Ruby
100 lines
1.8 KiB
Ruby
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?
|
|
|
|
# Return method name
|
|
#
|
|
# @return [Symbol]
|
|
#
|
|
# @api private
|
|
#
|
|
def name
|
|
node.children[self.class::NAME_INDEX]
|
|
end
|
|
|
|
private
|
|
|
|
# Return scope
|
|
#
|
|
# @return [Class, Module]
|
|
#
|
|
# @api private
|
|
#
|
|
def scope
|
|
context.scope
|
|
end
|
|
|
|
# Return subtype identifier
|
|
#
|
|
# @return [String]
|
|
#
|
|
# @api private
|
|
#
|
|
def subtype
|
|
"#{context.identification}#{self.class::SYMBOL}#{name}"
|
|
end
|
|
|
|
# Instance method subjects
|
|
class Instance < self
|
|
|
|
NAME_INDEX = 0
|
|
SYMBOL = '#'.freeze
|
|
|
|
# Test if method is public
|
|
#
|
|
# @return [true]
|
|
# if method is public
|
|
#
|
|
# @return [false]
|
|
# otherwise
|
|
#
|
|
# @api private
|
|
#
|
|
def public?
|
|
scope.public_method_defined?(name)
|
|
end
|
|
memoize :public?
|
|
|
|
private
|
|
|
|
end # Instance
|
|
|
|
# Singleton method subjects
|
|
class Singleton < self
|
|
|
|
NAME_INDEX = 1
|
|
SYMBOL = '.'.freeze
|
|
|
|
# Test if method is public
|
|
#
|
|
# @return [true]
|
|
# if method is public
|
|
#
|
|
# @return [false]
|
|
# otherwise
|
|
#
|
|
# @api private
|
|
#
|
|
def public?
|
|
scope.singleton_class.public_method_defined?(name)
|
|
end
|
|
memoize :public?
|
|
|
|
end # Singleton
|
|
|
|
end # Method
|
|
end # Subject
|
|
end # Mutant
|