Project

dark_prism

0.0
No commit activity in last 3 years
No release in over 3 years
Simple and straightforward event dispatching for ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 0.11.3
~> 10.0
>= 0
~> 0.59.2

Runtime

 Project Readme

DarkPrism

Simple and straightforward event dispatching for ruby.

Build Status Maintainability Test Coverage License: MIT

Installation

Add this line to your application's Gemfile:

gem 'dark_prism'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dark_prism

Usage

Configuration

Here is an example of a DarkPrism configuration file that can be placed under Rails' initializers directory.

DarkPrism.configure do |config|
  config.register_listeners(Listeners::Base)
  config.gcloud do |gcloud_config|
    gcloud_config.project_id = gcloud_project_id
    gcloud_config.credentials = credentials
  end
end

Listeners::Base class example:

module Listeners
  class Base
    def self.listeners
      {
        user_created: [Listeners::Users::Created.new]
      }.freeze
    end
  end
end

module Listeners
  module Users
    class Created
      include DarkPrism::Dispatch

      def user_created(user)
        dispatch_pubsub(:user_created, user)
      end
    end
  end
end

Once you've configured DarkPrism, dispatching events is quiet easy. First you need to include the Dispatch module as follows:

include DarkPrism::Dispatch

Once it's included, you can dispatch events through one the following three methods:

dispatch_event(event_name, obj)

This method dispatches an object asynchronously to all available listeners to the event.

Example:

dispatch_event(:my_event, some_object)

dispatch_pubsub(topic_name, message, attributes = nil)

This method dispatches an object synchronously to a google pubsub topic.

Example:

dispatch_pubsub(:my_event, some_object, { foo: :bar })

dispatch_pubsub_async(topic_name, message, attributes = nil)

This method dispatches an object asynchronously to a google pubsub topic.

Example:

dispatch_pubsub_async(:my_event, some_object, { foo: :bar })

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests.

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/sandboxws/dark_prism. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant 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 DarkPrism project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.