Has Notifications

Build Status

Simple notification system for Ruby on Rails.

Installation

Generate tables that are required by has_notification:

$ gem install has_notifications
$ rails generate has_notifications:migration
$ rake db:migrate

Usage

Model which will be notificated:

class User < ActiveRecord::Base
    has_notifications
end

Notification model:

class Notification < ActiveRecord::Base
    acts_as_notification
end

Notify:

vlad = User.create!(name: "Vlad")
notification = Notification.create!(message: "Hello, World!")

vlad.notify(notification)

Get all notifications:

vlad = User.first
vlad.all_notifications
=> [...]

Get all unwatched notifications:

vlad = User.first
vlad.unwatched_notifications
=> [...]

Get all watched notifications:

vlad = User.first
vlad.watched_notifications
=> [...]

Mark notification as watched:

vlad = User.first
notification = vlad.unwatched_notifications[0]
=> <...>
notification.mark_as_watched

Callbacks(blocks and lambdas aren't supported):

class User < ActiveRecord::Base
    has_notifications
    on_notification :callback

    def callback notification
        # fancy code...
    end
end

Contributing

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