diff --git a/config/initializers/listeners.rb b/config/initializers/listeners.rb index e394a76743..2a55fe25f3 100644 --- a/config/initializers/listeners.rb +++ b/config/initializers/listeners.rb @@ -1,16 +1,10 @@ # frozen_string_literal: true -Hyrax.publisher.subscribe(Hyrax::Listeners::AclIndexListener.new) Hyrax.publisher.subscribe(Hyrax::Listeners::ActiveFedoraAclIndexListener.new) unless Hyrax.config.disable_wings -Hyrax.publisher.subscribe(Hyrax::Listeners::BatchNotificationListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::FileMetadataListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::FileSetLifecycleListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::FileSetLifecycleNotificationListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::MemberCleanupListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::MetadataIndexListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::ObjectLifecycleListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::TrophyCleanupListener.new) -Hyrax.publisher.subscribe(Hyrax::Listeners::WorkflowListener.new) + +Hyrax.publisher.default_listeners.each do |listener| + Hyrax.publisher.subscribe(listener) +end # Publish events from old style Hyrax::Callbacks to trigger the listeners # When callbacks are removed and replaced with direct event publication, drop these blocks diff --git a/lib/hyrax/publisher.rb b/lib/hyrax/publisher.rb index e709107f3f..db8b0ec6a9 100644 --- a/lib/hyrax/publisher.rb +++ b/lib/hyrax/publisher.rb @@ -194,5 +194,21 @@ class Publisher # @since 3.2.0 # @macro a_registered_event register_event('object.file.uploaded') + + ## + # @return Array[Object] the listeners Hyrax subscribes by default. + def default_listeners + @default_listeners ||= + [Hyrax::Listeners::AclIndexListener.new, + Hyrax::Listeners::BatchNotificationListener.new, + Hyrax::Listeners::FileMetadataListener.new, + Hyrax::Listeners::FileSetLifecycleListener.new, + Hyrax::Listeners::FileSetLifecycleNotificationListener.new, + Hyrax::Listeners::MemberCleanupListener.new, + Hyrax::Listeners::MetadataIndexListener.new, + Hyrax::Listeners::ObjectLifecycleListener.new, + Hyrax::Listeners::TrophyCleanupListener.new, + Hyrax::Listeners::WorkflowListener.new].freeze + end end end diff --git a/spec/hyrax/publisher_spec.rb b/spec/hyrax/publisher_spec.rb new file mode 100644 index 0000000000..23bdeabd81 --- /dev/null +++ b/spec/hyrax/publisher_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +RSpec.describe Hyrax::Publisher do + subject(:publisher) { described_class.instance } # singleton instance + + describe "#default_listeners" do + it "returns a collection of listeners" do + # listeners can be any Object, so we can't verify they are valid here + expect(publisher.default_listeners).to be_a Enumerable + end + + it "returns the same collection on successive calls" do + expect(publisher.default_listeners).to eql publisher.default_listeners + end + end +end