Extracted an ugly finder method from Rate#for to a private method. #1920

This commit is contained in:
Eric Davis
2009-01-16 16:16:39 -08:00
parent 68b7df3237
commit 06f8258b38
+14 -7
View File
@@ -26,15 +26,22 @@ class Rate < ActiveRecord::Base
# API to find the Rate for a +user+ on a +project+ at a +date+
def self.for(user, project = nil, date = Date.today.to_s)
rate = Rate.find(:first,
:conditions => ["user_id IN (?) AND project_id IN (?) AND date_in_effect <= ?",
user.id,
project.id,
date
],
:order => 'date_in_effect DESC')
rate = self.rate_for_user_project_and_date(user, project, date)
return nil if rate.nil?
return rate.amount
end
private
def self.rate_for_user_project_and_date(user, project, date)
return Rate.find(:first,
:order => 'date_in_effect DESC',
:conditions => [
"user_id IN (?) AND project_id IN (?) AND date_in_effect <= ?",
user.id,
project.id,
date
])
end
end