Has Notifications
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
Contributing
- Take a look at TODO.txt
- Fork it ( https://github.com/vladzzag/has_notifications/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