@@ -6,7 +6,8 @@ module Cleaner
66 # Options:
77 #
88 # - :keeping - An `integer` indicating the number of versions to be kept for
9- # each item per date. Defaults to `1`.
9+ # each item per date. Defaults to `1`. The most recent matching versions
10+ # are kept.
1011 # - :date - Should either be a `Date` object specifying which date to
1112 # destroy versions for or `:all`, which will specify that all dates
1213 # should be cleaned. Defaults to `:all`.
@@ -30,12 +31,14 @@ def clean_versions!(options = {})
3031 # Returns a hash of versions grouped by the `item_id` attribute formatted
3132 # like this: {:item_id => PaperTrail::Version}. If `item_id` or `date` is
3233 # set, versions will be narrowed to those pointing at items with those ids
33- # that were created on specified date.
34+ # that were created on specified date. Versions are returned in
35+ # chronological order.
3436 def gather_versions ( item_id = nil , date = :all )
3537 unless date == :all || date . respond_to? ( :to_date )
3638 raise ArgumentError . new ( "`date` argument must receive a Timestamp or `:all`" )
3739 end
3840 versions = item_id ? PaperTrail ::Version . where ( :item_id => item_id ) : PaperTrail ::Version
41+ versions = versions . order ( PaperTrail . timestamp_field , :id )
3942 versions = versions . between ( date . to_date , date . to_date + 1 . day ) unless date == :all
4043
4144 # If `versions` has not been converted to an ActiveRecord::Relation yet,
0 commit comments