Class: Mutant::Mutator::Registry Private

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

Overview

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

Registry for mutators

Constant Summary collapse

RegistryError =

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

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



9
10
11
# File 'lib/mutant/mutator/registry.rb', line 9

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



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

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)


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

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