Class: Yael::Bus
- Inherits:
-
Object
- Object
- Yael::Bus
- Defined in:
- lib/yael/bus.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dispatch(name, stream:, payload:) ⇒ Object
- #process(event) ⇒ Object
- #routes ⇒ Object
- #routing(&block) ⇒ Object
Class Method Details
.shared ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/yael/bus.rb', line 6 def shared unless @shared @shared = Bus.new path = Rails.root.join("config/events.rb") if path.exist? reloader = Rails.configuration.file_watcher.new([path]) do load path end Rails.application.reloader.to_prepare do reloader.execute_if_updated end Rails.application.reloaders << reloader reloader.execute end end @shared end |
Instance Method Details
#dispatch(name, stream:, payload:) ⇒ Object
33 34 35 36 |
# File 'lib/yael/bus.rb', line 33 def dispatch(name, stream:, payload:) stream = Event.stream_for(stream) unless stream.is_a?(String) DispatchJob.perform_later(name: name, stream: stream, payload: payload, created_at: DateTime.current) end |
#process(event) ⇒ Object
38 39 40 41 42 |
# File 'lib/yael/bus.rb', line 38 def process(event) routes.each do |route| route.dispatch(event) if route.matches? event.name end end |
#routes ⇒ Object
25 26 27 |
# File 'lib/yael/bus.rb', line 25 def routes @routes ||= [] end |
#routing(&block) ⇒ Object
29 30 31 |
# File 'lib/yael/bus.rb', line 29 def routing(&block) @routes = DispatchMap.new(block).routes end |