Class: WCC::Contentful::Event::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/wcc/contentful/event.rb

Instance Method Summary collapse

Instance Method Details

#get(name) ⇒ Object



20
21
22
23
# File 'lib/wcc/contentful/event.rb', line 20

def get(name)
  @event_types ||= {}
  @event_types[name] || WCC::Contentful::Event::Unknown
end

#register(constant) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
# File 'lib/wcc/contentful/event.rb', line 25

def register(constant)
  name = constant.try(:type) || constant.name.demodulize
  raise ArgumentError, "Constant #{constant} does not define 'new'" unless constant.respond_to?(:new)

  @event_types ||= {}
  @event_types[name] = constant
end