Class: Cda::TemplatesRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/cda/templates_registry.rb

Direct Known Subclasses

Ccd::Registry

Instance Method Summary collapse

Constructor Details

#initialize(mappings = {}) ⇒ TemplatesRegistry

Returns a new instance of TemplatesRegistry.



2
3
4
# File 'lib/cda/templates_registry.rb', line 2

def initialize(mappings = {})
  @collection = mappings
end

Instance Method Details

#[](template_id) ⇒ Object



13
14
15
# File 'lib/cda/templates_registry.rb', line 13

def [](template_id)
  @collection[template_id]
end

#add(template_id, model_class) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/cda/templates_registry.rb', line 6

def add(template_id, model_class)
  raise ArgumentError, "template_id is nil" unless template_id
  raise "Already registered #{template_id}, #{model_class}" if @collection.key?(template_id)

  @collection[template_id] = model_class
end