Module: Housekeeping::Timestamps::ClassMethods

Defined in:
lib/housekeeping/timestamps.rb

Instance Method Summary collapse

Instance Method Details

#created_in_last(time) ⇒ Scope

Otu.created_in_last(2.weeks)

Returns:

  • (Scope)


69
70
71
# File 'lib/housekeeping/timestamps.rb', line 69

def created_in_last(time)
  where(created_at: time.ago..Time.now)
end

#created_last(number = 10) ⇒ Scope

Returns:

  • (Scope)


80
81
82
# File 'lib/housekeeping/timestamps.rb', line 80

def created_last(number = 10)
  limit(number).order(created_at: :DESC)
end

#created_this_weekScope

Returns:

  • (Scope)


48
49
50
# File 'lib/housekeeping/timestamps.rb', line 48

def created_this_week
  where(created_at: 1.week.ago..Time.now)
end

#created_todayScope

Returns:

  • (Scope)


58
59
60
# File 'lib/housekeeping/timestamps.rb', line 58

def created_today
  where(created_at: 1.day.ago..Time.now)
end

#first_createdScope

Returns:

  • (Scope)


28
29
30
# File 'lib/housekeeping/timestamps.rb', line 28

def first_created
  all.order(created_at: :asc).first
end

#first_updatedScope

Returns:

  • (Scope)


38
39
40
# File 'lib/housekeeping/timestamps.rb', line 38

def first_updated
  all.order(updated_at: :asc).first
end

#last_createdScope

Returns:

  • (Scope)


33
34
35
# File 'lib/housekeeping/timestamps.rb', line 33

def last_created
  all.order(created_at: :desc).first
end

#last_updatedScope

Returns:

  • (Scope)


43
44
45
# File 'lib/housekeeping/timestamps.rb', line 43

def last_updated
  all.order(updated_at: :desc).first
end

#updated_in_last(time) ⇒ Scope

Otu.created_in_last(1.month)

Returns:

  • (Scope)


75
76
77
# File 'lib/housekeeping/timestamps.rb', line 75

def updated_in_last(time)
  where(updated_at: time.ago..Time.now)
end

#updated_last(number = 10) ⇒ Scope

Returns:

  • (Scope)


85
86
87
# File 'lib/housekeeping/timestamps.rb', line 85

def updated_last(number = 10)
  limit(number).order(updated_at: :DESC)
end

#updated_this_weekScope

Returns:

  • (Scope)


53
54
55
# File 'lib/housekeeping/timestamps.rb', line 53

def updated_this_week
  where(updated_at: 1.week.ago..Time.now)
end

#updated_todayScope

Returns:

  • (Scope)


63
64
65
# File 'lib/housekeeping/timestamps.rb', line 63

def updated_today
  where(updated_at: 1.day.ago..Time.now)
end