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)


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

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

#created_last(number = 10) ⇒ Scope

Returns:

  • (Scope)


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

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

#created_this_weekScope

Returns:

  • (Scope)


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

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

#created_todayScope

Returns:

  • (Scope)


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

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

#first_createdScope

Returns:

  • (Scope)


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

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

#first_updatedScope

Returns:

  • (Scope)


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

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

#last_createdScope

Returns:

  • (Scope)


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

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

#last_updatedScope

Returns:

  • (Scope)


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

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

#updated_in_last(time) ⇒ Scope

Otu.created_in_last(1.month)

Returns:

  • (Scope)


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

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

#updated_last(number = 10) ⇒ Scope

Returns:

  • (Scope)


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

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

#updated_this_weekScope

Returns:

  • (Scope)


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

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

#updated_todayScope

Returns:

  • (Scope)


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

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

#where_dated_string(table, type) ⇒ Scope

Returns:

  • (Scope)


89
90
91
# File 'lib/housekeeping/timestamps.rb', line 89

def where_dated_string(table, type)
  "#{table}.#{type}ated_at >= ? and #{table}.#{type}ated_at <= ?"
end