Module: Reactor

Defined in:
lib/reactor/static_subscribers.rb,
lib/reactor.rb,
lib/reactor/errors.rb,
lib/reactor/version.rb,
lib/reactor/workers.rb,
lib/reactor/subscription.rb,
lib/reactor/workers/event_worker.rb,
lib/reactor/workers/mailer_worker.rb,
lib/reactor/models/concerns/subscribable.rb,
lib/reactor/workers/concerns/configuration.rb

Overview

MailerWorker has a bit more to do than EventWorker. It has to run the event, then if the output is a Mail::Message or the like it needs to deliver it like ActionMailer would

Defined Under Namespace

Modules: Publishable, StaticSubscribers, Subscribable, Workers Classes: Event, EventHandlerAlreadyDefined, Subscription, UnconfiguredWorkerError, UndeliverableMailError

Constant Summary collapse

SUBSCRIBERS =
{}.with_indifferent_access
BASE_VALIDATOR =

default behavior is to not actually validate anything

-> (_event) { }
VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.add_subscriber(event_name, worker_class) ⇒ Object



24
25
26
27
# File 'lib/reactor.rb', line 24

def add_subscriber(event_name, worker_class)
  subscribers[event_name] ||= []
  subscribers[event_name] << worker_class
end

.subscriber_namespaceObject



33
34
35
# File 'lib/reactor.rb', line 33

def subscriber_namespace
  Reactor::StaticSubscribers
end

.subscribersObject



20
21
22
# File 'lib/reactor.rb', line 20

def subscribers
  SUBSCRIBERS
end

.subscribers_for(event_name) ⇒ Object



29
30
31
# File 'lib/reactor.rb', line 29

def subscribers_for(event_name)
  Array(subscribers[event_name]) + Array(subscribers['*'])
end

.validator(block = nil) ⇒ Object

If you want, you can inject your own validator block in ‘config/initializers/reactor.rb`

Reactor.validator -> (event) { Validator.new(event).validate! }

If not, the default behavior is to do nothing. (see Reactor::BASE_VALIDATOR)



44
45
46
47
48
# File 'lib/reactor.rb', line 44

def validator(block = nil)
  @validator = block if block.present?

  @validator || BASE_VALIDATOR
end