Coder Social home page Coder Social logo

carrier's Introduction

Carrier

Carrier is result of extracting simple messaging functionality from one working Rails app.

Installiation

Insert into Gemfile

gem 'carrier'

Run bundler to bundle gems in the app

$ bundle update

Since Carrier is a Rails 3.1 mountable app, you need to define mount point like:

# config/routes.rb
mount Carrier::Engine => "/carrier" 

Install Carrier’s migrations and run them:

rake carrier:install:migrations
rake db:migrate

Carrier uses Unread to manage read/unread status of messages. So add this into your User model:

# app/models/user.rb
class User < ActiveRecord::Base
  # ...
  acts_as_reader
  # ...
end

Carrier works only for authenticated users expecting #current_user method somehow defined.
Carrier’s controllers namespaces are isolated, so to provide authentication procedure yielding #current_user (before_filter is most common way) add it to Carrier::ApplicationController like:

# your app's root/app/controllers/carrier/application_controller.rb
module Carrier
  class ApplicationController < ActionController::Base
    before_filter :authenticate_user! # If using Devise
  end
end

This ensures that Carrier will be aware of current authenticated user.

Point your browser to your_apps’s url/carrier, fx:

http://localhost/carrier

and you are on the go!

Prerequisites

  • Rails 3.1
  • Carrier has been tested with Devise as authentication system. Any other solution providing #current_user should be just fine too.
  • Carrier has been tested to work with MySQL and PostgreSQL.
    It doesn’t work with SQLite3, because sqlite3 doesn’t serialize fields (maybe this is the issue of current gem environment only). Scope’s queries are using the most basic Arel features so it should be easy to use any other ORM.

Design overview

The Carrier design is very simple:

It has messages and chains (Message model, and Chain model). Message model has chain_id i.e. messages are simply grouped in chains. Chains are non-threaded, each chain is just a linear sequence of messages.

All queries to messages and their chains are being done using scopes with joins and includes so performance is expected to be fast (review it and advice how accomplish it even better!).

Carrier doesn’t support deletion of messages yet. Instead it supports archivation of chains (Chain has #archived_for field to store serialized array of user’s ids).

Configuration

Carrier’s templates are written in I18n way. Carrier has two locales :en and :ru pre-written. If you change locale in config/application.rb Carrier will try to find corresponding rules from locale’s yml files

More coming…

Quick try

Try dummy app located in spec/ folder. Clone repo, then:

# edit Gemfile:
gem 'mysql' or gem 'pg'
bundle 
cd spec/dummy
rake reset_db # shortcut for rake db:drop => create => migrate => seed
rails s
http://localhost/carrier

TODO

  • Deletion along with archivation
  • ORM’s support
  • More and better tests

Contributors

  • Stanislaw Pankevich

Copyright

Copyright © 2011 Stanislaw Pankevich. See LICENSE for details.

carrier's People

Contributors

stanislaw avatar

Stargazers

Scott J Shea avatar

Watchers

Scott J Shea avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.