Class: Mutant::Reporter::CLI::Registry
- Inherits:
-
Module
- Object
- Module
- Mutant::Reporter::CLI::Registry
- Defined in:
- lib/mutant/reporter/cli/registry.rb
Overview
Mixin to generate registry semantics
Class Method Summary collapse
-
.new ⇒ Registry
private
Return new registry.
Instance Method Summary collapse
-
#handle(subject, handler) ⇒ self
private
Register handler for class.
-
#included(host) ⇒ undefined
private
Hook called when module is included.
-
#lookup(subject) ⇒ Object
private
Lookup handler.
Class Method Details
.new ⇒ Registry
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.
Return new registry
14 15 16 |
# File 'lib/mutant/reporter/cli/registry.rb', line 14 def self.new super({}) end |
Instance Method Details
#handle(subject, handler) ⇒ 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 handler for class
26 27 28 29 30 |
# File 'lib/mutant/reporter/cli/registry.rb', line 26 def handle(subject, handler) raise "Duplicate registration of #{subject}" if registry.key?(subject) registry[subject] = handler self end |
#included(host) ⇒ 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.
Hook called when module is included
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mutant/reporter/cli/registry.rb', line 63 def included(host) super object = self host.class_eval do define_singleton_method(:lookup, &object.method(:lookup)) private_class_method :lookup define_singleton_method(:handle) do |subject| object.handle(subject, self) end private_class_method :handle end end |
#lookup(subject) ⇒ Object
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 handler
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mutant/reporter/cli/registry.rb', line 44 def lookup(subject) current = subject until current.equal?(Object) if registry.key?(current) return registry.fetch(current) end current = current.superclass end raise "No printer for: #{subject}" end |