Module: Housekeeping::Timestamps::ClassMethods

Defined in:
lib/housekeeping/timestamps.rb

Instance Method Summary (collapse)

Instance Method Details

- (Scope) created_in_last(time)

Otu.created_in_last(2.weeks)

Returns:

  • (Scope)


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

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

- (Scope) created_last(number = 10)

Returns:

  • (Scope)


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

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

- (Scope) created_this_week

Returns:

  • (Scope)


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

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

- (Scope) created_today

Returns:

  • (Scope)


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

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

- (Scope) first_created

Returns:

  • (Scope)


23
24
25
# File 'lib/housekeeping/timestamps.rb', line 23

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

- (Scope) first_updated

Returns:

  • (Scope)


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

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

- (Scope) last_created

Returns:

  • (Scope)


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

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

- (Scope) last_updated

Returns:

  • (Scope)


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

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

- (Scope) updated_in_last(time)

Otu.created_in_last(1.month)

Returns:

  • (Scope)


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

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

- (Scope) updated_last(number = 10)

Returns:

  • (Scope)


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

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

- (Scope) updated_this_week

Returns:

  • (Scope)


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

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

- (Scope) updated_today

Returns:

  • (Scope)


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

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

- (Scope) where_dated_string(table, type)

Returns:

  • (Scope)


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

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