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


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

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

Raises:

  • (ArgumentError)

    raises argument error when mutator class cannot be found


46
47
48
49
50
51
# File 'lib/mutant/mutator/registry.rb', line 46

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


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

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