Module: Mongoid::Utils::Sortable::ClassMethods

Defined in:
lib/mongoid/utils/sortable.rb

Instance Method Summary collapse

Instance Method Details

#fresh_by(param) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# 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