Class: Mutant::Mutator::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/mutator/registry.rb

Overview

Registry for mutators

Constant Summary collapse

RegistryError =

Raised when the type is an invalid type

Class.new(TypeError)

Instance Method Summary collapse

Constructor Details

#initializeundefined

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.

Initialize object



11
12
13
# File 'lib/mutant/mutator/registry.rb', line 11

def initialize
  @registry = {}
end

Instance 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



43
44
45
46
47
48
# File 'lib/mutant/mutator/registry.rb', line 43

def lookup(node)
  type = node.type
  @registry.fetch(type) do
    fail RegistryError, "No mutator to handle: #{type.inspect}"
  end
end

#register(type, mutator) ⇒ 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:Mutator)

Returns:

  • (self)


26
27
28
29
30
31
# File 'lib/mutant/mutator/registry.rb', line 26

def register(type, mutator)
  fail RegistryError, "Invalid type registration: #{type}" unless AST::Types::ALL.include?(type)
  fail RegistryError, "Duplicate type registration: #{type}" if @registry.key?(type)
  @registry[type] = mutator
  self
end