• Stars
    star
    34
  • Rank 741,926 (Top 16 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Publish and Subscribe for Crystal objects

Evented

A micro library providing Crystal objects with Publish-Subscribe capabilities

Build Status

  • Decouple core business logic from external concerns in Hexagonal style architectures
  • Use as an alternative to callbacks and Observers
  • Connect objects based on context without permanence
  • React to events synchronously

Installation

Add this to your application's shard.yml:

dependencies:
  evented:
    github: krisleech/evented

Usage

Publishing

By including Evented::Publisher your objects get broadcast and subscribe methods.

broadcast can be called from within your object whenever you want to broadcast a significant event.

require "evented"

class MyPublisher
  include Evented::Publisher

  def call(input)
    result = do_something(input)
    broadcast(:something_happened, result)
  end
end

Subscribing

To subscribe an object to receive events include Evented::Subscriber and provide your own on_event method which will receive 2 arguments, the event_name and payload.

require "evented"

class MySubscriber
  include Evented::Subscriber

  def on_event(event_name, payload)
    # ...
  end
end

To subscribe the listener to a publisher:

publisher = MyPublisher.new
publisher.subscribe(MySubscriber.new)

publisher.call("hello")

In the above example the subscriber will have on_event(:something_happened, "hello") called.

Development

Specs

crystal spec

Automatically run Specs

ls ./**/*.cr | entr crystal spec

Contributing

  1. Fork it ( https://github.com/krisleech/evented/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

More Repositories

1

wisper

A micro library providing Ruby objects with Publish-Subscribe capabilities
Ruby
3,231
star
2

vimfiles

Ruby/Rails centric vimfiles with support for Git, RVM and more.
Vim Script
182
star
3

wisper-activerecord

Transparently publish all model changes to subscribers
Ruby
99
star
4

wisper-sidekiq

Asynchronous event publishing for Wisper using Sidekiq
Ruby
81
star
5

wisper-rspec

RSpec matchers and stubbing for Wisper
Ruby
61
star
6

not_found

Allows you to rescue ActiveRecord::RecordNotFound for a specific model
Ruby
60
star
7

chalk_dust

Subscriptions connect models, events build activity feeds.
Ruby
47
star
8

wisper-async

Async broadcasting for Wisper
Ruby
34
star
9

wisper-activejob

Provides asynchronous event publishing to Wisper using ActiveJob
Ruby
34
star
10

wisper-celluloid

Provides async event broadcasting to Wisper using Celluloid
Ruby
17
star
11

turbo-vim

Vim with support for Tmux, Ruby/Rails, Rspec, Git and RVM.
Vim Script
12
star
12

tmuxinator

Generate tmux configurations for your projects
Ruby
11
star
13

medicine

Simple dependency injection for Ruby objects
Ruby
7
star
14

jQuery-Character-Counter

Count and Limit the number of characters in a <textarea>
JavaScript
6
star
15

neovim-config

My NeoVIM configuration
Vim Script
5
star
16

Git-Web

A web interface for Git Repositories
Ruby
4
star
17

wisper-message_bus

Relay Wisper events as JSON to other processes via MessageBus
Ruby
4
star
18

axe

A small stream processing framework for routing Kafka topics to parallelised Ruby objects.
Ruby
4
star
19

seeds

Generate seeds.rb file from existing database tables
Ruby
4
star
20

wisper-attributes

Transparently publish attribute changes to subscribers
Ruby
4
star
21

wisper-testing

Helpers for testing Wisper publisher/subscribers.
Ruby
4
star
22

Install-Gems

Install gems listed in a text file generated by 'gem list'. Useful after doing a clean OS install.
3
star
23

conduit

An event store for Ruby
Ruby
3
star
24

vim_switcher

Switch between multiple vimfiles
Ruby
3
star
25

ma

Event Driven Ruby [MIRROR]
Ruby
3
star
26

Reinstall-Gems

Reinstall all your gems which have C extensions, useful for upgrading to 64 bit, ie. Mac 10.6 Snow Leopard
3
star
27

wisper-visualize

Visualizations for Wisper events
Ruby
3
star
28

wisper-rabbitmq

Relay Wisper events to RabbitMQ
Ruby
2
star
29

wisper_next

The next version of Wisper [MIRROR]
Ruby
2
star
30

skeletor

A starting point for a Rails app which uses qcore and qcms gems
JavaScript
2
star
31

backup_data

Engine style plugin which offers backup of database and files
Ruby
2
star
32

harbour

Terminate process listening on a port
Ruby
2
star
33

Persistent-Hash

Simple example used to teach several Ruby coding techniques
Ruby
2
star
34

wisper-relay

Relay wisper events to the outside world, for example a message queue.
Ruby
2
star
35

pipes

Toy app using pipes to communicate between two processes.
Shell
2
star
36

spec_requirer

Explicitly require files and manage LOAD_PATH in tests which do not boot a framework
Ruby
2
star
37

qwerty

This is a work in progress
Ruby
2
star
38

rake-deploy

Automated deploy and backup for Rails Application
1
star
39

qcms

Qwerty CMS (Rails Engine distributed as a Gem)
Ruby
1
star
40

Pushy

Demonstrates the use of long lived HTTP connections to allow the server (Sinatra) to *push* data to the client (JQuery)
JavaScript
1
star
41

wisper-presentation

Presentation about Wisper gem using Vim
Vim Script
1
star
42

qcore

Qwerty Core - authorisation and authentication in a Rails engine in a Gem
Ruby
1
star
43

detachment

Transparent Sub / Pub broker for Ruby objects
Ruby
1
star
44

s_and_c

One letter aliases for Rails Server and Console
Ruby
1
star
45

polymorphia

Associate any ActiveRecord object to another
Ruby
1
star
46

domain3

Service, Form and Validator objects.
Ruby
1
star
47

wisper-bubble

Event bubbling for Wisper
Ruby
1
star
48

Git-By-Proxy

Simple rake tasks to rope in a graphic designer who doesn't want to use version control and (S)FTP's stuff up to the server instead.
1
star
49

pomodoro

Promodoro timer in your shell
Ruby
1
star
50

WebbyGen

Generate skeleton directory structure plus files for a Webby site
1
star
51

scnsht

Take screenshot (selection), copy to Dropbox public folder, copy URL to clipboard
Shell
1
star
52

rails-stack

Rails stack for solo server using Sprinkle
Ruby
1
star
53

jukebox

Jukebox service
Ruby
1
star
54

QwertyChef

Chef Solo Provisioning for Rails
Ruby
1
star
55

Path-Finder

A Rails plugin which extends ActiveRecord to allow self-referential models (eg. acts_as_tree) to maintain a textual path representing itself and its ancestors.
Ruby
1
star