Skip to content

Commit bc75015

Browse files
committed
Extract timestamp validation into a class method
1 parent 2b8d736 commit bc75015

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app/repositories/feed_repository.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ def self.fetch_by_ids(ids)
88
end
99

1010
def self.update_last_fetched(feed, timestamp)
11-
is_invalid_timestamp = timestamp.nil? ||
12-
timestamp.year < MIN_YEAR ||
13-
(feed.last_fetched && timestamp <= feed.last_fetched)
14-
15-
unless is_invalid_timestamp
11+
unless self.is_invalid_timestamp(timestamp, feed.last_fetched)
1612
feed.last_fetched = timestamp
1713
feed.save
1814
end
@@ -30,5 +26,12 @@ def self.set_status(status, feed)
3026
def self.list
3127
Feed.order('lower(name)')
3228
end
33-
end
3429

30+
private
31+
32+
def self.is_invalid_timestamp(new_timestamp, current_timestamp)
33+
new_timestamp.nil? ||
34+
new_timestamp.year < MIN_YEAR ||
35+
(current_timestamp && new_timestamp <= current_timestamp)
36+
end
37+
end

0 commit comments

Comments
 (0)