2013-06-04 23:44:17 +02:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
|
|
|
|
# Mutator for required arguments
|
|
|
|
class Argument < self
|
|
|
|
handle(:arg)
|
|
|
|
|
|
|
|
UNDERSCORE = '_'.freeze
|
2013-06-21 15:04:44 +02:00
|
|
|
|
|
|
|
children :name
|
2013-06-04 23:44:17 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Perform dispatch
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def dispatch
|
|
|
|
emit_name_mutation
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit name mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_name_mutation
|
2013-12-04 18:48:20 +01:00
|
|
|
return if skip?
|
2015-08-13 22:02:04 -04:00
|
|
|
emit_name(:"#{UNDERSCORE}#{name}")
|
2013-06-04 23:44:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Test if argument mutation is skipped
|
|
|
|
#
|
2014-06-15 19:27:57 +00:00
|
|
|
# @return [Boolean]
|
2013-06-04 23:44:17 +02:00
|
|
|
def skip?
|
|
|
|
name.to_s.start_with?(UNDERSCORE)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Mutator for optional arguments
|
|
|
|
class Optional < self
|
|
|
|
|
|
|
|
handle(:optarg)
|
|
|
|
|
2013-06-21 15:52:46 +02:00
|
|
|
children :name, :default
|
2013-06-04 23:44:17 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Perform dispatch
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def dispatch
|
|
|
|
emit_name_mutation
|
|
|
|
emit_required_mutation
|
|
|
|
emit_default_mutations
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit required mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_required_mutation
|
|
|
|
emit(s(:arg, name))
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Optional
|
|
|
|
|
|
|
|
end # Argument
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|