Class: Mammoth::Registry
- Inherits:
-
Object
- Object
- Mammoth::Registry
- Defined in:
- lib/mammoth/registry.rb
Overview
Small explicit registry for built-in and extension-provided adapters.
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#fetch(name) ⇒ Object
Fetch a registered adapter.
-
#initialize(namespace) ⇒ Registry
constructor
A new instance of Registry.
-
#names ⇒ Array<String>
Registered adapter names.
-
#register(name, adapter) ⇒ Object
Register an adapter under a stable name.
Constructor Details
#initialize(namespace) ⇒ Registry
Returns a new instance of Registry.
9 10 11 12 |
# File 'lib/mammoth/registry.rb', line 9 def initialize(namespace) @namespace = namespace @entries = {} end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
6 7 8 |
# File 'lib/mammoth/registry.rb', line 6 def entries @entries end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/mammoth/registry.rb', line 6 def namespace @namespace end |
Instance Method Details
#fetch(name) ⇒ Object
Fetch a registered adapter.
30 31 32 33 |
# File 'lib/mammoth/registry.rb', line 30 def fetch(name) key = normalize_name(name) entries.fetch(key) { raise ConfigurationError, "unknown #{namespace} adapter: #{key}" } end |
#names ⇒ Array<String>
Returns registered adapter names.
36 37 38 |
# File 'lib/mammoth/registry.rb', line 36 def names entries.keys.sort end |
#register(name, adapter) ⇒ Object
Register an adapter under a stable name.
19 20 21 22 23 24 |
# File 'lib/mammoth/registry.rb', line 19 def register(name, adapter) key = normalize_name(name) raise ConfigurationError, "#{namespace} adapter already registered: #{key}" if entries.key?(key) entries[key] = adapter end |