18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/timestamp_scopes.rb', line 18
def create_timestamp_scopes_for_column(name)
full_name = "#{quoted_table_name}.#{name}"
short_name = shorten_column_name(name)
scope :"#{short_name}_to", lambda { |date| where("#{full_name} <= ?", date) }
scope :"#{short_name}_from", lambda { |date| where("#{full_name} >= ?", date) }
scope :"#{short_name}_after", lambda { |date| where("#{full_name} > ?", date) }
scope :"#{short_name}_before", lambda { |date| where("#{full_name} < ?", date) }
scope :"#{short_name}_between", lambda { |from, to| where("#{full_name} BETWEEN ? AND ?", from, to) }
scope :"#{short_name}_not_between", lambda { |from, to| where("#{full_name} NOT BETWEEN ? AND ?", from, to) }
scope :"#{short_name}_within", lambda { |from, to| where("#{full_name} > ? AND #{full_name} < ?", from, to) }
scope :"#{short_name}_not_within", lambda { |from, to| where("#{full_name} <= ? OR #{full_name} >= ?", from, to) }
end
|