free_mutant/lib/mutant/strategy.rb

93 lines
1.3 KiB
Ruby
Raw Normal View History

# encoding: utf-8
2012-11-21 18:10:50 -05:00
module Mutant
# Abstract base class for killing strategies
2013-04-17 23:31:21 -04:00
class Strategy
2014-01-17 18:25:16 -05:00
include AbstractType, Adamantium::Flat, Equalizer.new
2014-01-17 18:15:42 -05:00
REGISTRY = {}
# Lookup strategy for name
#
# @param [String] name
#
# @return [Strategy]
# if found
#
# @api private
#
def self.lookup(name)
REGISTRY.fetch(name)
end
# Register strategy
#
# @param [String] name
#
# @return [undefined]
#
# @api private
#
def self.register(name)
REGISTRY[name] = self
end
private_class_method :register
# Perform strategy setup
#
2013-01-15 17:46:05 -05:00
# @return [self]
#
# @api private
#
def setup
2013-09-02 16:02:51 -04:00
self
end
# Perform strategy teardown
#
2013-01-15 17:46:05 -05:00
# @return [self]
#
# @api private
#
def teardown
2013-09-02 16:02:51 -04:00
self
end
2012-11-21 18:10:50 -05:00
# Kill mutation
#
# @param [Mutation] mutation
2012-11-21 18:10:50 -05:00
#
# @return [Killer]
#
# @api private
#
def kill(mutation)
2012-11-21 18:10:50 -05:00
killer.new(self, mutation)
end
private
# Return killer
#
# @return [Class:Killer]
#
# @api private
#
def killer
self.class::KILLER
2012-11-21 18:10:50 -05:00
end
2013-06-14 14:54:02 -04:00
2014-01-17 18:15:42 -05:00
# Null strategy that never kills a mutation
class Null < self
register 'null'
KILLER = Killer::Null
end # Null
2013-06-14 14:54:02 -04:00
end # Strategy
2014-01-17 18:15:42 -05:00
2013-06-14 14:54:02 -04:00
end # Mutant