Class: ConcurrentPipeline::Registry
- Inherits:
-
Object
- Object
- ConcurrentPipeline::Registry
- Defined in:
- lib/concurrent_pipeline/registry.rb
Instance Method Summary collapse
Instance Method Details
#build(type, attributes) ⇒ Object
5 6 7 |
# File 'lib/concurrent_pipeline/registry.rb', line 5 def build(type, attributes) lookup.fetch(type).new(attributes) end |
#register(type, klass) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/concurrent_pipeline/registry.rb', line 9 def register(type, klass) if lookup.key?(type) raise <<~TXT Duplicate type: #{type} for class #{klass.name}. Use the `as:` \ option to avoid this collision, eg `model(MyModel, as: :MyModel). TXT end lookup[type] = klass end |
#type_for(type) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/concurrent_pipeline/registry.rb', line 20 def type_for(type) return type if lookup.key?(type) reverse_lookup = lookup.invert return reverse_lookup[type] if reverse_lookup.key?(type) raise ArgumentError, "Unknown type: #{type}" end |