Sha256: 69f3a2b11544215607a1faadfa953c702b43e59d3131aa21302e2e55ddc9c109

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Hyrax
  module Listeners
    ##
    # Listens for events related to the PCDM Object lifecycles.
    class ObjectLifecycleListener
      ##
      # Called when 'object.deleted' event is published
      # @param [Dry::Events::Event] event
      # @return [void]
      def on_object_deleted(event)
        # Accessing a non-existent key on a Dry::Events::Event will raise a KeyError; hence
        # we cast the event to a hash
        event = event.to_h
        object_id = event[:object]&.id || event[:id]
        ContentDeleteEventJob.perform_later(object_id.to_s, event[:user])
      end

      ##
      # Called when 'object.deposited' event is published
      # @param [Dry::Events::Event] event
      # @return [void]
      def on_object_deposited(event)
        ContentDepositEventJob.perform_later(event[:object], event[:user])
      end

      ##
      # Called when 'object.metadata.updated' event is published
      # @param [Dry::Events::Event] event
      # @return [void]
      def on_object_metadata_updated(event)
        ContentUpdateEventJob.perform_later(event[:object], event[:user])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyrax-5.0.2 app/services/hyrax/listeners/object_lifecycle_listener.rb
hyrax-5.0.1 app/services/hyrax/listeners/object_lifecycle_listener.rb
hyrax-5.0.0 app/services/hyrax/listeners/object_lifecycle_listener.rb
hyrax-5.0.0.rc3 app/services/hyrax/listeners/object_lifecycle_listener.rb