lib/mutant/mutator.rb in mutant-0.8.0 vs lib/mutant/mutator.rb in mutant-0.8.1
- old
+ new
@@ -11,11 +11,10 @@
# @param [Mutator] parent
#
# @return [self]
#
# @api private
- #
def self.each(input, parent = nil, &block)
return to_enum(__method__, input, parent) unless block_given?
REGISTRY.lookup(input).new(input, parent, block)
self
@@ -24,32 +23,29 @@
# Register node class handler
#
# @return [undefined]
#
# @api private
- #
def self.handle(*types)
types.each do |type|
REGISTRY.register(type, self)
end
end
private_class_method :handle
- # Return input
+ # Mutation input
#
# @return [Object]
#
# @api private
- #
attr_reader :input
- # Return input
+ # Parent context of input
#
# @return [Object]
#
# @api private
- #
attr_reader :parent
private
# Initialize object
@@ -59,11 +55,10 @@
# @param [#call(node)] block
#
# @return [undefined]
#
# @api private
- #
def initialize(input, parent, block)
@input, @parent, @block = input, parent, block
@seen = Set.new
guard(input)
dispatch
@@ -74,11 +69,10 @@
# @param [Object] object
#
# @return [Boolean]
#
# @api private
- #
def new?(object)
!@seen.include?(object)
end
# Add object to guarded values
@@ -86,31 +80,28 @@
# @param [Object] object
#
# @return [undefined]
#
# @api private
- #
def guard(object)
@seen << object
end
# Dispatch node generations
#
# @return [undefined]
#
# @api private
- #
abstract_method :dispatch
# Emit generated mutation if object is not equivalent to input
#
# @param [Object] object
#
# @return [undefined]
#
# @api private
- #
def emit(object)
return unless new?(object)
guard(object)
@@ -122,31 +113,28 @@
# @param [Parser::AST::Node] node
#
# @return [self]
#
# @api private
- #
def emit!(node)
@block.call(node)
self
end
# Run input with mutator
#
# @return [undefined]
#
# @api private
- #
def run(mutator)
mutator.new(input, self, method(:emit))
end
# Shortcut to create a new unfrozen duplicate of input
#
# @return [Object]
#
# @api private
- #
def dup_input
input.dup
end
end # Mutator