module ActiveEventStore
Attributes
event_store[RW]
Underlying RailsEventStore
Public Class Methods
config()
click to toggle source
# File lib/active_event_store.rb, line 23 def config @config ||= Config.new end
mapping()
click to toggle source
# File lib/active_event_store.rb, line 19 def mapping @mapping ||= Mapping.new end
publish(event, **options)
click to toggle source
# File lib/active_event_store.rb, line 52 def publish(event, **options) event_store.publish event, **options end
subscribe(subscriber = nil, to: nil, sync: false)
click to toggle source
# File lib/active_event_store.rb, line 27 def subscribe(subscriber = nil, to: nil, sync: false) subscriber ||= Proc.new to ||= infer_event_from_subscriber(subscriber) if subscriber.is_a?(Module) if to.nil? raise ArgumentError, "Couldn't infer event from subscriber. " \ "Please, specify event using `to:` option" end identifier = if to.is_a?(Class) && ActiveEventStore::Event >= to # register event mapping.register_event to to.identifier else to end subscriber = SubscriberJob.from(subscriber) unless sync event_store.subscribe subscriber, to: [identifier] end
Private Class Methods
infer_event_from_subscriber(subscriber)
click to toggle source
# File lib/active_event_store.rb, line 58 def infer_event_from_subscriber(subscriber) event_class_name = subscriber.name.split("::").yield_self do |parts| # handle explicti top-level name, e.g. ::Some::Event parts.shift if parts.first.empty? # drop last part – it's a unique subscriber name parts.pop parts.last.sub!(/^On/, "") parts.join("::") end event_class_name.safe_constantize end
Public Instance Methods
symbolize_keys()
click to toggle source
# File lib/active_event_store/mapper.rb, line 8 def symbolize_keys RubyEventStore::TransformKeys.symbolize(self) end