Take the 2008 Git User's Survey and help out! [ hide ]

public
Description: Plugin for querying by dates on ActiveRecord models
Clone URL: git://github.com/joshuaclayton/acts_as_archivable.git
Search Repo:
100644 33 lines (24 sloc) 0.888 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
ActsAsArchivable
================
 
ActsAsArchivable is a collection of methods that I found myself using quite a bit related
to models with time-stamped columns. Initial things were blog entries in regards to archives,
but I found that I was using these more and more in various ways throughout many models.
 
This library requires ActiveRecord.
 
  class Entry < ActiveRecord::Base
    acts_as_archivable :order => 'DESC'
    has_many :comments, :dependent => :destroy
  end
 
  class Comment < ActiveRecord::Base
    acts_as_archivable :on => :replied_on
    belongs_to :entry
  end
 
From here, you have quick access to records related to date.
 
  Entry.by_date :year => 2007
  Entry.by_date Date.today
  Entry.by_date '5/1/2007'
 
  Entry.oldest
  Entry.newest
 
  Entry.recent 2.weeks
  Entry.recent 3.months
  Entry.recent (3.months - 1.week)
 
  Entry.between '5/10/2007', Date.today