Skip to content

smakagon/hanami-interactor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pub/Sub functionality for Hanami Framework

Allows to publish events:

class SignUp
  include Hanami::Publisher

  def call
    broadcast(:user_signed_up, first_name: 'John', last_name: 'Doe')
  end
end

Allows to subscribe for events:

class WelcomeMailer
  include Hanami::Subscriber

  subscribe_to :user_signed_up

  def user_signed_up(params)
    puts "Processing event with params: #{params}"
  end
end

If we run this code:

SignUp.new.call

It will publish :user_signed_up event and WelcomeMailer#user_signed_up will be called with params: { first_name: 'John', last_name: 'Doe' }

So response will be:

Processing event with params: {:first_name=>"John", :last_name=>"Doe"}

Uses wisper gem to implement pub/sub.

Created as a Proof of concept, feedback is welcomed!

Idea of having Pub/Sub for Hanami was described here: https://discourse.hanamirb.org/t/hanami-2-0-ideas/306/9

About

PubSub implementation for Hanami framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages