lib/maitredee/subscriber.rb in maitredee-0.8.3 vs lib/maitredee/subscriber.rb in maitredee-0.8.4
- old
+ new
@@ -2,24 +2,44 @@
module Maitredee
##
# Inherit from this class to easily subscrive to messages:
#
- # class RecipeSubscriber < Maitredee::Subscriber
- # subscribe_to :recipes do
- # event(:update) # by default this calls the event_name, #delete
- # end
+ # class RecipeSubscriber < Maitredee::Subscriber
+ # # this is the topic name
+ # subscribe_to :recipes do
#
- # def update
- # # do some work
- # end
- # end
+ # # this is the event name optionally say which method to use to process
+ # event(:create, to: create)
#
- # If you want to process a message manually
+ # # event_name will be used as the method name if it is a valid method name, otherwise to: must be set
+ # event(:delete)
#
- # RecipePublisher.process()
+ # # for empty event name just use nil
+ # event(nil, to: :process)
#
- # Note that `call` is a class method, `process` is an instance method.
+ # # you can specify a catch all route
+ # default_event to: :process
+ # end
+ #
+ # # optional initializer to do message pre processing
+ # # def initialize(message)
+ # # super
+ # # # do business here
+ # # end
+ #
+ # def create
+ # Recipe.create!(message.body)
+ # end
+ #
+ # def process
+ # Recipe.find(message.body[:id]).update(message.body)
+ # end
+ #
+ # def delete
+ # Recipe.find(message.body[:id]).destroy
+ # end
+ # end
class Subscriber
EventConfig = Struct.new(
:action,
:event_name,
keyword_init: true