2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-06-04 17:44:17 -04:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
|
|
|
|
# Mutator for required arguments
|
|
|
|
class Argument < self
|
|
|
|
handle(:arg)
|
|
|
|
|
|
|
|
UNDERSCORE = '_'.freeze
|
2013-06-21 09:04:44 -04:00
|
|
|
|
|
|
|
children :name
|
2013-06-04 17:44:17 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Perform dispatch
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
|
|
|
return if skip?
|
|
|
|
emit_name_mutation
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit name mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_name_mutation
|
2013-06-24 16:10:40 -04:00
|
|
|
Mutator::Util::Symbol.each(name, self) do |name|
|
2013-06-21 09:52:46 -04:00
|
|
|
emit_name(name)
|
2013-06-04 17:44:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test if argument mutation is skipped
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if argument should not get mutated
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def skip?
|
|
|
|
name.to_s.start_with?(UNDERSCORE)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Mutator for optional arguments
|
|
|
|
class Optional < self
|
|
|
|
|
|
|
|
handle(:optarg)
|
|
|
|
|
2013-06-21 09:52:46 -04:00
|
|
|
children :name, :default
|
2013-06-04 17:44:17 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Perform dispatch
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
|
|
|
emit_name_mutation
|
|
|
|
emit_required_mutation
|
|
|
|
emit_default_mutations
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit required mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_required_mutation
|
|
|
|
emit(s(:arg, name))
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Optional
|
|
|
|
|
|
|
|
end # Argument
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|