Encapsulate the concept of staleness into its own class

Extract it from a single helper method and wrap it in a method object.
This lets us add tests around it and then (later) split the domain
concerns from the view concerns.
This commit is contained in:
Matt Rogers 2013-03-07 22:22:17 -06:00
parent d7e9b384f7
commit ccf5323588
2 changed files with 89 additions and 0 deletions

18
lib/staleness.rb Normal file
View file

@ -0,0 +1,18 @@
require 'active_support/all'
class Staleness
def self.days_stale(item, current_user)
if item.due || item.completed?
return ""
elsif item.created_at < current_user.time - (current_user.prefs.staleness_starts * 3).days
return " stale_l3"
elsif item.created_at < current_user.time - (current_user.prefs.staleness_starts * 2).days
return " stale_l2"
elsif item.created_at < current_user.time - (current_user.prefs.staleness_starts).days
return " stale_l1"
else
return ""
end
end
end