0.0
No commit activity in last 3 years
No release in over 3 years
A tally plugin for Ohm that keeps counts of records for every value of an attribute
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

ohm-tallyable

Gem Version Build Status Code Climate

A tally plugin for Ohm that keeps counts of records for every value of an attribute

Setup

  1. Include the Callbacks and Tallyable modules in your model:

     include Ohm::Callbacks 
     include Ohm::Tallyable
    
  2. Add a tally to your model with the following line:

     tally :category
    

You will need to resave every model if they already exist.

Usage

To query the tallies, use the leaderboard class method.

>> Post.leaderboard(:category)
=> [["Personal", 2], ["Work", 1]]

Advanced Usage

You can also partition the tally by a certain attribute:

tally :category, :by => :site_id

You will need to provide a value for this attribute every time you check the leaderboard:

Post.leaderboard(:category, :site_id => 'ar') 

If for any reason you find yourself having to recompute the tallies, you can do so with this line of code:

Post.retally(:category)

Requirements

This plugin works with Ohm versions higher than 0.1.3.

Acknowledgements

Many thanks to Damian Janowski (https://github.com/djanowski) who took care to explain me the details of coding an Ohm plugin and providing many ideas on how to handle certain cases.