7 def find(method, options = {})
8 @block.call(method, options)
12 def year_finder(finder, year)
13 new do |method, options|
14 start = Time.local(year)
15 finish = start.next_year
16 add_condition(options, "published_at >= ? and published_at < ?", start, finish)
17 finder.find(method, options)
21 def month_finder(finder, year, month)
22 new do |method, options|
23 start = Time.local(year, month)
24 finish = start.next_month
25 add_condition(options, "published_at >= ? and published_at < ?", start, finish)
26 finder.find(method, options)
30 def day_finder(finder, year, month, day)
31 new do |method, options|
32 start = Time.local(year, month, day)
33 finish = start.tomorrow
34 add_condition(options, "published_at >= ? and published_at < ?", start, finish)
35 finder.find(method, options)
41 def concat_conditions(a, b)
42 sql = "(#{ [a.shift, b.shift].compact.join(") AND (") })"
47 def add_condition(options, *condition)
48 old = options[:conditions] || []
49 conditions = concat_conditions(old, condition)
50 options[:conditions] = conditions