lib/reactor.rb in reactor-0.19.0 vs lib/reactor.rb in reactor-1.0.0

- old
+ new

@@ -7,18 +7,15 @@ require "reactor/static_subscribers" require "reactor/workers/concerns/configuration" require "reactor/workers" require "reactor/subscription" require "reactor/models" -require "reactor/controllers" require "reactor/event" -# FIXME: should only be included in test environments -require "reactor/testing" - module Reactor SUBSCRIBERS = {}.with_indifferent_access + BASE_VALIDATOR = -> (_event) { } # default behavior is to not actually validate anything module_function def subscribers SUBSCRIBERS @@ -33,7 +30,20 @@ Array(subscribers[event_name]) + Array(subscribers['*']) end def subscriber_namespace Reactor::StaticSubscribers + end + + # + # 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) + # + def validator(block = nil) + @validator = block if block.present? + + @validator || BASE_VALIDATOR end end