Class: ActionFigure::FormatRegistry::Formats
- Inherits:
-
Object
- Object
- ActionFigure::FormatRegistry::Formats
- Defined in:
- lib/action_figure/format_registry.rb
Overview
Stores the mapping of format names to formatter modules.
Instance Method Summary collapse
- #fetch(name) ⇒ Object
-
#initialize ⇒ Formats
constructor
A new instance of Formats.
- #register_formatter(**formatters) ⇒ Object
Constructor Details
#initialize ⇒ Formats
Returns a new instance of Formats.
10 11 12 |
# File 'lib/action_figure/format_registry.rb', line 10 def initialize @formats = Concurrent::Map.new end |
Instance Method Details
#fetch(name) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/action_figure/format_registry.rb', line 18 def fetch(name) @formats.fetch(name) do raise ArgumentError, "Unknown formatter: #{name}. Register it with ActionFigure.register_formatter(#{name}: MyFormatter)." end end |
#register_formatter(**formatters) ⇒ Object
14 15 16 |
# File 'lib/action_figure/format_registry.rb', line 14 def register_formatter(**formatters) formatters.each { |name, mod| @formats[name] = mod } end |