Module: Newshound::Warnings
- Defined in:
- lib/newshound/warnings.rb,
lib/newshound/warnings/base.rb
Defined Under Namespace
Classes: Base
Class Attribute Summary collapse
-
.registry ⇒ Hash
readonly
Access the registry of registered adapters.
Class Method Summary collapse
-
.clear_registry! ⇒ Object
Clear the registry (primarily for testing).
-
.register(name, adapter_class) ⇒ Object
Register a warning adapter class with a symbolic name.
-
.source(source) ⇒ Warnings::Base
Get a warning source adapter instance.
Class Attribute Details
.registry ⇒ Hash (readonly)
Access the registry of registered adapters
15 16 17 |
# File 'lib/newshound/warnings.rb', line 15 def registry @registry end |
Class Method Details
.clear_registry! ⇒ Object
Clear the registry (primarily for testing)
51 52 53 |
# File 'lib/newshound/warnings.rb', line 51 def clear_registry! @registry = {} end |
.register(name, adapter_class) ⇒ Object
Register a warning adapter class with a symbolic name
23 24 25 |
# File 'lib/newshound/warnings.rb', line 23 def register(name, adapter_class) @registry[name.to_sym] = adapter_class end |
.source(source) ⇒ Warnings::Base
Get a warning source adapter instance
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/newshound/warnings.rb', line 35 def source(source) return source unless source.is_a?(Symbol) # First check the registry if @registry.key?(source) return @registry[source].new end # Fall back to constant lookup (like Exceptions module) constant = constants.find { |c| c.to_s.gsub(/(?<!^)([A-Z])/, "_\\1").downcase == source.to_s } raise "Invalid warning source: #{source}" unless constant const_get(constant).new end |