module Mongoid::Utils::Sortable::ClassMethods

Public Instance Methods

fresh_by(param) click to toggle source
# File lib/mongoid/utils/sortable.rb, line 11
def fresh_by(param)
  range = case param
    when 'day'; Time.now.at_beginning_of_day..Time.now
    when 'week'; Time.now.at_beginning_of_week..Time.now
    when 'month'; Time.now.at_beginning_of_month..Time.now
    when 'year'; Time.now.at_beginning_of_year..Time.now
  end

  between(:id.in => BSON::ObjectId.from_time(range.first)..BSON::ObjectId.from_time(range.last))
end