Class: Mutant::Mutator::Registry
- Inherits:
-
Object
- Object
- Mutant::Mutator::Registry
- 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
-
#initialize ⇒ undefined
constructor
private
Initialize object.
-
#lookup(node) ⇒ Class
private
Lookup mutator class for node.
-
#register(type, mutator) ⇒ self
private
Register mutator class for AST node class.
Constructor Details
#initialize ⇒ undefined
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
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
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 |