Project

eventifier

0.01
No commit activity in last 3 years
No release in over 3 years
Tracks and logs events and sends notifications of events on Active Record models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.5.0
~> 2.11.0
~> 0.20
~> 3.0.0.beta2

Runtime

~> 4.0.0
>= 2.0.4
>= 1.8.6
>= 4.0.3
~> 0.1
 Project Readme

Eventifier

Event tracking and notifying for active record models

Features

Tracks and logs events on active record objects
Send notifications of events

Example


class EventTracking
  include Eventifier::EventTracking

  def initialize
    events_for Post do
      track_on [:create, :update, :destroy], attributes: { except: %w(updated_at) }
      notify group: :members, on: :create
      notify group: :commenters, on: :update, unless: ->post,author { post.age > 1.week }
    end

    events_for Announcement do
      track_on :create
      notify group: :members, on: :create, if: ->announcement,admin { announcement.is_important? }
    end
  end
end

That’s it!

Installation

Add Eventifier to your Gemfile


  # Gemfile
  gem "eventifier"

And run bundle install

Add Eventifier to your Gemfile


  rails generate eventifier:install
  rake eventifier:install:migrations

Add notifications indicator in interface

Eventifier provides a notification tool for your users.


  # app/views/layouts/application.erb
  <div class="notifications"></div>

Add stylesheets


  # app/assets/stylesheets/application.scss
  /*= require eventifier/notifications*/

Add javascript


  # app/assets/javascripts/application.coffee
  #= require eventifier/notifications

  new NotificationDropdown el: $(".notifications")

Add the required routes


  # config/routes.rb
  mount Eventifier::Engine => '/'

Customise views


  # app/views/eventifier/dropdown/_comment.haml
  %a{ href: "#{root_url}#{url_for([object.commentable.user, object.commentable])}" }
    = image_tag object.user.photo.thumb.url, class: 'avatar'
    #{object.user.username} commented on your post

You can create a custom view for each context

Dropdown notification: app/views/eventifier/dropdown/comment.haml
Email notification: app/views/eventifier/email/
comment.haml

Helpers made available to these views are:

notification: The notification object
Eventifier::Notification(event: event, user: user_being_notified, parent: parent_notification, sent: email_sent_flag)

event: The event object
Eventifier::Event(user: event_owner, eventable: object_for_event, verb: [:create, :update, :destroy], change_data: {"name" => [“Bill”, “Bob”]}, groupable: grouped_object)

object: The object the event was created for

Sending of emails

Firstly, you’ll need to set the FROM address for the Eventifier mailer


  # config/initializers/eventifier.rb
  Eventifier.mailer_sender = 'Funways <team@funways.me>'

You want to add a scheduled task to run the following task every x minutes


  rake eventifier:email:deliver

Customise email settings descriptions


  # config/locales/events.en.yml
  en:
    events:
      labels:
        preferences:
          default: "All notifications"
          create_relationships_notify_followed: "When you get a new follower"

Requirements

  • ActiveRecord

Turbolinks

Turbolinks removes the body of the page, which is where our dropdown notifications box sits. We’ll need to re-render it and point it at the holding element when the page changes.

```
$ →
window.notifications = new NotificationDropdown el: $(‘.notifications’), pollTime: 60

$(document).on “page:change”, →
notifications.el = $(‘.notifications’)
notifications.render()
```

Testing

Creating the database:

  • createdb eventifier

Spec


  rspec spec

Contributors

  • PJ Murray