No commit activity in last 3 years
No release in over 3 years
Record historical values any attributes in mongoid documents
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.6.2
>= 0

Runtime

 Project Readme

Mongoid Historicals

Record a snapshot of current values to reference later as historical values.

Installation

Add to your Gemfile

gem 'mongoid-historicals', :require => 'mongoid/historicals'

Usage

Here is an example of how to track the week-to-week score for the players in my fictional MMORPGFPS:

class Player
  include Mongoid::Document
  include Mongoid::Historicals

  field :username, type: String
  field :score,    type: Integer

  historicals :score, :max => 52, :frequency => :weekly
end

In a cron task, I could run the following every Sunday before midnight:

Player.all.each do |player|
  player.record!
end

Then, I could show each player's historical score like this:

<h2>Your Current Score: <%= @player.score %></h2>
<p>Your Score Last Week: <%= @player.historical(:score, 1.week.ago) %> / Difference: <%= @player.historical_difference(:score, 1.week.ago) %></p>