3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/steem_data/acts_as_temporal.rb', line 3
def self.included(base)
base.scope :starting, lambda { |with, field = :timestamp, not_inverted = true|
r = where(field.gt => with, field.lt => Time.now.utc)
not_inverted ? r : where(:_id.nin => r.distinct(:_id))
}
base.scope :ending, lambda { |with, field = :timestamp, not_inverted = true|
r = where(field.gt => Time.at(0), field.lt => with)
not_inverted ? r : where(:_id.nin => r.distinct(:_id))
}
base.scope :betwixt, lambda { |starting, ending, field = :timestamp, not_inverted = true|
r = where(field.gt => starting, field.lt => ending)
not_inverted ? r : where(:_id.nin => r.distinct(:_id))
}
base.scope :today, lambda { |field = :timestamp|
starting(1.day.ago.utc, field)
}
base.scope :yesterday, lambda { |field = :timestamp|
betwixt(2.days.ago.utc, 1.day.ago.utc, field)
}
end
|