lib/emittance.rb in emittance-1.1.0 vs lib/emittance.rb in emittance-2.0.0.pre.1

- old
+ new

@@ -4,24 +4,28 @@ require 'emittance/errors' require 'emittance/helpers/string_helpers' require 'emittance/helpers/constant_helpers' require 'emittance/event_lookup' +require 'emittance/topic_lookup' require 'emittance/dispatcher' require 'emittance/brokerage' require 'emittance/broker' require 'emittance/event' require 'emittance/emitter' require 'emittance/watcher' +require 'emittance/middleware' require 'emittance/notifier' require 'emittance/action' ## # The base namespace for this library. You can do some basic configuration stuff by calling methods on its singleton. # module Emittance class << self + attr_reader :event_routing_strategy + # Enable eventing process-wide def enable! Emittance::Brokerage.enable! end @@ -34,31 +38,62 @@ def enabled? Emittance::Brokerage.enabled? end # @return [Class] the currently enabled broker class - def broker - Emittance::Brokerage.broker + def default_broker + Emittance::Brokerage.default_broker end + alias broker default_broker + + def dispatcher_for(*args) + Emittance::Brokerage.dispatcher_for(*args) + end + + alias dispatcher dispatcher_for + # @return [Class] the dispatcher attached to the currently enabled broker - def dispatcher - broker.dispatcher + def default_dispatcher + default_broker.dispatcher end - # @param [identifier] the identifier that can be used to identify the broker you wish to use + # @param identifier [#to_sym] the identifier that can be used to identify the broker you wish to use def use_broker(identifier) Emittance::Brokerage.use_broker identifier end + def default_broker=(identifier) + Emittance::Brokerage.default_broker = identifier + end + + # Emittance.use_middleware MyMiddleware + # Emittance.use_middleware MyOtherMiddleware, MyCoolMiddleware + # + # @param middlewares [Array<Class>] each middleware you wish to run. + def use_middleware(*middlewares) + Emittance::Middleware.register middlewares + end + + # Removes all middlewares from the app. + def clear_middleware! + Emittance::Middleware.clear_registrations! + end + # Not yet implemented! Remove nocov and private flags when finished. # :nocov: # @private def suppress(&_blk) raise NotImplementedError, "This isn't working yet!" # Emittance::Dispatcher.suppress(&blk) end # :nocov: + + def event_routing_strategy=(new_strategy) + @event_routing_strategy = new_strategy + Emittance::Event.lookup_strategy = new_strategy + Emittance::Dispatcher.routing_strategy = new_strategy + end end end Emittance.use_broker :synchronous