class WCC::Contentful::Events
WCC::Contentful::Events
is a singleton which rebroadcasts Contentful update events. You can subscribe to these events in your initializer using the [wisper gem syntax](github.com/krisleech/wisper). All published events are in the namespace WCC::Contentful::Event
.
Public Class Methods
instance()
click to toggle source
# File lib/wcc/contentful/events.rb, line 13 def self.instance @instance ||= new end
new()
click to toggle source
# File lib/wcc/contentful/events.rb, line 17 def initialize _attach_listeners end
Public Instance Methods
rebroadcast(event)
click to toggle source
# File lib/wcc/contentful/events.rb, line 21 def rebroadcast(event) type = event.dig('sys', 'type') raise ArgumentError, "Unknown event type #{event}" unless type.present? broadcast(type, event) end
Private Instance Methods
_attach_listeners()
click to toggle source
# File lib/wcc/contentful/events.rb, line 30 def _attach_listeners publishers = [ WCC::Contentful::Services.instance.sync_engine ] publishers << WCC::Contentful::WebhookController if defined?(Rails) publishers.each do |publisher| publisher.subscribe(self, with: :rebroadcast) if publisher.present? end end