Module: ActiverecordTimeScopes::ClassMethods

Defined in:
lib/activerecord_time_scopes.rb

Instance Method Summary collapse

Instance Method Details

#created_after(time) ⇒ Object



12
13
14
15
# File 'lib/activerecord_time_scopes.rb', line 12

def created_after(time)
  time = time.created_at if time.is_a?(ActiveRecord::Base)
  where('created_at > ?', time)
end

#created_before(time) ⇒ Object



7
8
9
10
# File 'lib/activerecord_time_scopes.rb', line 7

def created_before(time)
  time = time.created_at if time.is_a?(ActiveRecord::Base)
  where('created_at < ?', time)
end

#created_between(time, time2) ⇒ Object



17
18
19
# File 'lib/activerecord_time_scopes.rb', line 17

def created_between(time, time2)
  created_after(time).created_before(time2)
end

#created_last_monthObject



41
42
43
44
# File 'lib/activerecord_time_scopes.rb', line 41

def created_last_month
  # This is different, since months can be different lengths:
  created_between((Time.zone.now.beginning_of_month - 1.day).beginning_of_month, Time.zone.now.beginning_of_month)
end

#created_last_weekObject



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

def created_last_week
  created_between(Time.zone.now.beginning_of_week - 1.week, Time.zone.now.beginning_of_week)
end

#created_last_yearObject



50
51
52
# File 'lib/activerecord_time_scopes.rb', line 50

def created_last_year
  created_between(Time.zone.now.beginning_of_year - 1.years, Time.zone.now.beginning_of_year)
end

#created_this_monthObject



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

def created_this_month
  created_after(Time.zone.now.beginning_of_month)
end

#created_this_weekObject



29
30
31
# File 'lib/activerecord_time_scopes.rb', line 29

def created_this_week
  created_after(Time.zone.now.beginning_of_week)
end

#created_this_yearObject



46
47
48
# File 'lib/activerecord_time_scopes.rb', line 46

def created_this_year
  created_after(Time.zone.now.beginning_of_year)
end

#created_todayObject



21
22
23
# File 'lib/activerecord_time_scopes.rb', line 21

def created_today
  created_after(Time.zone.now.beginning_of_day)
end

#created_yesterdayObject



25
26
27
# File 'lib/activerecord_time_scopes.rb', line 25

def created_yesterday
  created_between(Time.zone.now.beginning_of_day - 1.days,Time.zone.now.beginning_of_day)
end

#updated_after(time) ⇒ Object



59
60
61
62
# File 'lib/activerecord_time_scopes.rb', line 59

def updated_after(time)
  time = time.updated_at if time.is_a?(ActiveRecord::Base)
  where('updated_at > ?', time)
end

#updated_before(time) ⇒ Object



54
55
56
57
# File 'lib/activerecord_time_scopes.rb', line 54

def updated_before(time)
  time = time.updated_at if time.is_a?(ActiveRecord::Base)
  where('updated_at < ?', time)
end

#updated_between(time, time2) ⇒ Object



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

def updated_between(time, time2)
  updated_after(time).updated_before(time2)
end

#updated_last_monthObject



88
89
90
91
# File 'lib/activerecord_time_scopes.rb', line 88

def updated_last_month
  # This is different, since months can be different lengths:
  updated_between((Time.zone.now.beginning_of_month - 1.day).beginning_of_month, Time.zone.now.beginning_of_month)
end

#updated_last_weekObject



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

def updated_last_week
  updated_between(Time.zone.now.beginning_of_week - 1.week, Time.zone.now.beginning_of_week)
end

#updated_last_yearObject



97
98
99
# File 'lib/activerecord_time_scopes.rb', line 97

def updated_last_year
  updated_between(Time.zone.now.beginning_of_year - 1.years, Time.zone.now.beginning_of_year)
end

#updated_this_monthObject



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

def updated_this_month
  updated_after(Time.zone.now.beginning_of_month)
end

#updated_this_weekObject



76
77
78
# File 'lib/activerecord_time_scopes.rb', line 76

def updated_this_week
  updated_after(Time.zone.now.beginning_of_week)
end

#updated_this_yearObject



93
94
95
# File 'lib/activerecord_time_scopes.rb', line 93

def updated_this_year
  updated_after(Time.zone.now.beginning_of_year)
end

#updated_todayObject



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

def updated_today
  updated_after(Time.zone.now.beginning_of_day)
end

#updated_yesterdayObject



72
73
74
# File 'lib/activerecord_time_scopes.rb', line 72

def updated_yesterday
  updated_between(Time.zone.now.beginning_of_day - 1.days,Time.zone.now.beginning_of_day)
end