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
30
31
32
33
34
35
36
37
38
39
|
# File 'app/models/sbds/acts_as_transaction.rb', line 3
def self.included(base)
def base.table_name_prefix; 'sbds_tx_'; end
def base.default_scope
order(timestamp: :asc)
end
base.scope :block, lambda { |block_num|
where(block_num: block_num)
}
base.scope :starting, lambda { |with, field = :timestamp, not_inverted = true|
r = where(field => with..Time.now.utc)
not_inverted ? r : where.not(r)
}
base.scope :ending, lambda { |with, field = :timestamp, not_inverted = true|
r = where(field => Time.at(0)..with)
not_inverted ? r : where.not(r)
}
base.scope :betwixt, lambda { |starting, ending, field = :timestamp, not_inverted = true|
r = where(field => starting..ending)
not_inverted ? r : where.not(r)
}
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
|