lib/dry/events/publisher.rb in dry-events-0.3.0 vs lib/dry/events/publisher.rb in dry-events-0.4.0
- old
+ new
@@ -1,16 +1,13 @@
# frozen_string_literal: true
-require 'concurrent/map'
+require "dry/core"
+require "dry/events/constants"
+require "dry/events/event"
+require "dry/events/bus"
+require "dry/events/filter"
-require 'dry/core/class_attributes'
-
-require 'dry/events/constants'
-require 'dry/events/event'
-require 'dry/events/bus'
-require 'dry/events/filter'
-
module Dry
module Events
# Exception raised when the same publisher is registered more than once
#
# @api public
@@ -25,13 +22,16 @@
InvalidSubscriberError = Class.new(StandardError) do
# @api private
def initialize(object_or_event_id)
case object_or_event_id
when String, Symbol
- super("you are trying to subscribe to an event: `#{object_or_event_id}` that has not been registered")
+ super(
+ "you are trying to subscribe to an event: `#{object_or_event_id}` "\
+ "that has not been registered"
+ )
else
- super('you try use subscriber object that will never be executed')
+ super("you try use subscriber object that will never be executed")
end
end
end
UnregisteredEventError = Class.new(StandardError) do
@@ -72,11 +72,11 @@
#
# # this will publish "users.created" event with its payload
# create_user.call(name: "Jane")
#
# @api public
- class Publisher < Module
+ class Publisher < ::Module
include Dry::Equalizer(:id)
# Internal publisher registry, which is used to identify them globally
#
# This allows us to have listener classes that can subscribe to events
@@ -100,16 +100,17 @@
#
# @raise PublisherAlreadyRegisteredError
#
# @api public
def self.[](id)
- raise PublisherAlreadyRegisteredError.new(id) if registry.key?(id)
+ raise PublisherAlreadyRegisteredError, id if registry.key?(id)
new(id)
end
# @api private
def initialize(id)
+ super()
@id = id
end
# Hook for inclusions/extensions
#