Module: Shamu::Events::Support
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/shamu/events/support.rb
Overview
Add event dispatching support to a Services::Service
Dependencies collapse
-
#events_service ⇒ Events::EventsService
The events service to publish messages to.
Instance Method Summary collapse
-
#event!(message, channel: event_channel)
Publish the given
messageto the #events_service. -
#event_channel ⇒ String
The channel to publish events to.
Instance Attribute Details
#events_service ⇒ Events::EventsService
Returns the events service to publish messages to.
17 |
# File 'lib/shamu/events/support.rb', line 17 attr_dependency :events_service, Events::EventsService |
Instance Method Details
#event!(message, channel: event_channel)
This method returns an undefined value.
Publish the given message to the #events_service.
34 35 36 |
# File 'lib/shamu/events/support.rb', line 34 def event!( , channel: event_channel ) events_service.publish channel, end |
#event_channel ⇒ String
The channel to publish events to. Defaults to the transformed name of the service class.
Users::UsersService => users
Users::ProfileService => users/profile
Users::Profiles::ProfilesService => users/profiles
48 49 50 51 52 53 54 55 56 |
# File 'lib/shamu/events/support.rb', line 48 def event_channel @event_channel ||= begin base_name = self.class.name || "Events" parts = base_name.split( "::" ) parts[-1].sub!( /Service$/, "" ) parts.pop if parts[-1] == parts[-2] || ( parts.length > 1 && parts[-1].blank? ) parts.join( "/" ).underscore end end |