Class: Mutest::Registry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mutest/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 mapping AST types to classes

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/mutest/registry.rb', line 9

def initialize
  super({})
end

Instance Method Details

#lookup(type) ⇒ 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 class for node

Parameters:

  • type (Symbol)

Returns:

  • (Class)

Raises:

  • (ArgumentError)

    raises argument error when class cannot be found



37
38
39
40
41
# File 'lib/mutest/registry.rb', line 37

def lookup(type)
  contents.fetch(type) do
    fail RegistryError, "No entry for: #{type.inspect}"
  end
end

#register(type, klass) ⇒ 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 class for AST node class

Parameters:

  • type (Symbol)
  • class (Class)

Returns:

  • (self)


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

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