Module: Mutant::Mutator::Registry

Defined in:
lib/mutant/mutator/registry.rb

Overview

Registry for mutators

Constant Summary collapse

InvalidTypeError =

Raised when the type is an invalid type

Class.new(TypeError)
DuplicateTypeError =

Raised when the type is a duplicate

Class.new(ArgumentError)

Class Method Summary collapse

Class Method Details

.lookup(node) ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lookup mutator class for node

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (Class)

Raises:

  • (ArgumentError)

    raises argument error when mutator class cannot be found



39
40
41
42
43
44
# File 'lib/mutant/mutator/registry.rb', line 39

def self.lookup(node)
  type = node.type
  registry.fetch(type) do
    raise ArgumentError, "No mutator to handle: #{type.inspect}"
  end
end

.register(type, mutator_class) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register mutator class for AST node class

Parameters:

  • type (Symbol)
  • mutator_class (Class)

Returns:

  • (self)


21
22
23
24
25
26
# File 'lib/mutant/mutator/registry.rb', line 21

def self.register(type, mutator_class)
  assert_valid_type(type)
  assert_unique_type(type)
  registry[type] = mutator_class
  self
end