free_mutant/lib/mutant/strategy/method_expansion.rb

52 lines
960 B
Ruby
Raw Normal View History

2013-01-13 16:29:07 -05:00
module Mutant
class Strategy
module MethodExpansion
# Run method name expansion
#
# @param [Symbol] name
#
# @return [Symbol]
#
# @api private
#
def self.run(name)
name = map(name) || expand(name)
end
# Return mapped name
#
# @param [Symbol] name
#
# @return [Symbol]
# if name was mapped
#
# @return [nil]
# otherwise
#
# @api private
#
def self.map(name)
OPERATOR_EXPANSIONS[name]
end
private_class_method :map
2013-02-22 14:46:22 -05:00
REGEXP = /#{Regexp.union(*METHOD_POSTFIX_EXPANSIONS.keys)}\z/.freeze
2013-01-13 16:29:07 -05:00
# Return expanded name
#
# @param [Symbol] name
#
# @return [Symbol]
#
# @api private
#
def self.expand(name)
name.to_s.sub(REGEXP, METHOD_POSTFIX_EXPANSIONS).to_sym
2013-01-13 16:29:07 -05:00
end
private_class_method :expand
end
end
end