Sha256: 97fb05d34550a89d5fcd2f86bea838d82ba1f906c51ddcd24c375f6b73378b90
Contents?: true
Size: 990 Bytes
Versions: 33
Compression:
Stored size: 990 Bytes
Contents
# frozen_string_literal: true require 'wisper' require 'singleton' # 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](https://github.com/krisleech/wisper). # All published events are in the namespace WCC::Contentful::Event. class WCC::Contentful::Events include Wisper::Publisher def self.instance @instance ||= new end def initialize _attach_listeners end def rebroadcast(event) type = event.dig('sys', 'type') raise ArgumentError, "Unknown event type #{event}" unless type.present? broadcast(type, event) end private 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 end
Version data entries
33 entries across 33 versions & 1 rubygems