/pushable-rails

Send model updates to Pusher

Primary LanguageRubyMIT LicenseMIT

pushable-rails

Send model updates to Pusher

Installation

Add this line to your application's Gemfile:

gem 'pushable-rails', require: 'pushable'

And then execute:

$ bundle

Usage

Include the Pushable module in your activerecord models like this:

class DummyModel < ActiveRecord::Base
  include Pushable
end

Now every time you create, update or destroy DummyModels your app will send the corresponding notifications to pusher.

Events

Channel: pusher

  • Create dummy_model.destroy

  • Update dummy_model.update

  • Destroy dummy_model.destroy

The payload will be the output of the model instance to_json. If defined, a serializer will be used (eg. DummyModelSerializer).

Including Pushable will also add client_id as a virtual attribute. Your client can use this attribute to distinguish not yet saved records. To add the client_id attribute to the model json you can include PushableSerializer in your ActiveModel::Serializers, like this:

class DummyModelSerializer < ActiveModel::Serializer
  include PushableSerializer
end

Integrations

This library works well with ember-pushable

Contributing

  1. Fork it ( http://github.com/matteodepalo/pushable-rails/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 new Pull Request