besked
Event System for notifications similar to ActiveSupport Instrumentation.
Installation
Add this to your application's shard.yml
:
dependencies:
besked:
github: ragmaanir/besked
Usage
require "besked"
Global event system
subscriber_called = false
Besked::Global.subscribe(Besked, "test") do |cls, name, event|
subscriber_called = true
end
assert !subscriber_called
Besked::Global.publish(Besked, "test", Besked::Event.new)
assert subscriber_called
Local pub/sub
class MyPub
include Besked::Publisher
end
class MySub
include Besked::Subscriber
getter? received
def initialize
@received = false
end
def receive(type : String, name : String, event : Besked::Event)
@received = true
end
end
def test_local_publishers_and_subscribers
pub = MyPub.new
sub = MySub.new
pub.subscribe(sub)
assert !sub.received?
pub.publish(MyPub, "test", Besked::Event.new)
assert sub.received?
end
Development
TODO Write development instructions here
Contributing
- Fork it ( https://github.com/ragmaanir/besked/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Ragmaanir - creator, maintainer