mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-15 16:56:32 +01:00
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:
parent
d7e9b384f7
commit
ccf5323588
2 changed files with 89 additions and 0 deletions
18
lib/staleness.rb
Normal file
18
lib/staleness.rb
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue