Project

notify_me

0.0
No commit activity in last 3 years
No release in over 3 years
This friendly library gives you generic notifications in your Rails app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.5.1
~> 1.3.7

Runtime

>= 3.2.0
 Project Readme

Gem Version Code Climate Build Status

Notify Me

This is a gem that provides simple and generic notifications that can have 0 or more actions associated with them.

Installation:

Add to Gemfile

gem 'notify_me', '0.0.4'

Now install and run your migrations

rake notify_me:install:migrations
rake db:migrate

Usage:

    class User < ActiveRecord::Base
        has_many_notifications
        ...
    end
    
    class Task < ActiveRecord::Base
        ...
    end
    
    class TaskSwap < ActiveRecord::Base
        belongs_to :from, class_name: "User"
        belongs_to :to,     class_name: "User"
        belongs_to :task
    
        def accept_swap(action)
            ...
        end
    
        def reject_swap(action)
            ...
        end
    end

A user wants to request a task swap

    swap_task = TaskSwap.create(...)
    notification = NotifyMe::Notification.create(message: "John Doe would like to swap tasks with you")
    user.notifications << notification
    
    notification.actions.create(notification: notification, commandable: swap_task, commandable_action: "accept_swap", name: "Accept")
    notification.actions.create(notification: notification, commandable: swap_task, commandable_action: "reject_swap", name: "Reject")

Likely in some controller somewhere

    action = Action.find(params[:id])
    action.run_action() # if this was the action created above, this would call swap_task.accept_swap(action)

License

Copyright (c) 2013, Notify Me is developed and maintained by Sam Clopton, and is released under the open MIT Licence.