No commit activity in last 3 years
No release in over 3 years
Minimal event framework based on Observable.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.14.1
~> 13.0

Runtime

 Project Readme

Tests Maintainability Coverage Status

TurboTestEvents

TurboTestEvents is a minimal event framework for Ruby based on Observable.

Installation

Add this line to your application's Gemfile:

gem 'turbo_test_events'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install turbo_test_events

Usage

Publish an event

payload = {created_at: Time.now}
TurboTest::EventRegistry["event_1"].publish(payload)

Subscribe to an event

Implement subscriber class with the update callback method:

class Subscriber
  def update(event_payload)
    # Process event
  end
end

Create a subscriber and subscribe it to the event:

subscriber = Subscriber.new
TurboTest::EventRegistry["event_1"].subscribe(subscriber)

You can have a custom update callback method with:

TurboTest::EventRegistry["event_1"].subscribe(subscriber, :method_name)

class CustomSubscriber
  def method_name(event_payload)
    # Process event
  end
end

Unsubscribe from an event

TurboTest::EventRegistry["event_1"].unsubscribe(subscriber)

Unsubscribe all subscribers from an event

TurboTest::EventRegistry["event_1"].unsubscribe_all

Multithreading Notes

  • You can publish events from different threads.
  • You can add and remove subscribers in different threads.
  • There are no guarantees about the thread that will execute the subscriber callback.
  • You should synchronize any internal data of the subscriber when modifying it.
  • You should synchronize any data of the event payload when modifying it.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. 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 tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dunkelbraun/turbo_test_events. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the TurboTestEvents project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.