Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nerdgeschoss/yael
Yael is Yet Another Event Library based on top of ActiveJob. It helps you dispatching events asynchronously in your code base and react to them just like routing in Rails.
https://github.com/nerdgeschoss/yael
Last synced: 2 months ago
JSON representation
Yael is Yet Another Event Library based on top of ActiveJob. It helps you dispatching events asynchronously in your code base and react to them just like routing in Rails.
- Host: GitHub
- URL: https://github.com/nerdgeschoss/yael
- Owner: nerdgeschoss
- Created: 2021-02-01T12:09:06.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-22T09:29:09.000Z (about 3 years ago)
- Last Synced: 2024-10-18T15:49:57.960Z (3 months ago)
- Language: Ruby
- Size: 13.7 KB
- Stars: 1
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yael
Yael is **Y**et **A**nother **E**vent **L**ibrary based on top of ActiveJob. It helps you dispatching events asynchronously in your code base and react to them just like routing in Rails.
## Usage
Define your routes in `config/events.rb` like this:```ruby
Yael::Bus.shared.routing do
dispatch :order_confirmed, to: "order_mailer.confirm", delay: 5.minutes, queue: :low_priority
dispatch :order_confirmed, to: "slack"
end
```Now include the publisher in your class and dispatch events:
```ruby
class Order < ApplicationRecord
include Yael::Publisherdef confirm_order
publish :order_confirmed, ip: some_id, some_other_data: data
end
endclass Slack
def self.on_order_confirmed(ip:)
# send a notification to slack
end
end
```Calling `confirm_order` now will invoke `OrderMailer.confirm` and `Slack.notify_order`.
You can also request historical events of an object: `Yael::Event.for(Order.find(id))` will return all events recorded.
### Some Things to Keep in Mind
- the subscriber signature does not have to exactly match the published payload - yael will return all matching parameters
- everything is executed asynchronously inside of a job, even dispatching events
- you can not only publish from `ActiveRecord` models, but from any class by providing a stream name: `Yael::Bus.shared.dispatch(:event_name, stream: "my_stream", payload: {})`## Installation
Add this line to your application's Gemfile:
```ruby
gem 'yael'
```And then execute:
```bash
bundle install
```Generate a migration for your database:
```ruby
rails generate yael:install
rails db:migrate
```## Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yael. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/yael/blob/master/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Yael project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yael/blob/master/CODE_OF_CONDUCT.md).