From 3d7b8592ea2362e46cdd3d51da9278e3e742a251 Mon Sep 17 00:00:00 2001 From: Francesco Marano Date: Wed, 3 Jun 2015 15:32:34 +0200 Subject: [PATCH] Defined function to get last db update and removed redundant code --- lib/common/common_helper.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/common/common_helper.rb b/lib/common/common_helper.rb index f20e7665..0330c21b 100644 --- a/lib/common/common_helper.rb +++ b/lib/common/common_helper.rb @@ -79,10 +79,17 @@ def missing_db_file? false end +def last_update + date = nil + if File.exists?(LAST_UPDATE_FILE) + content = File.read(LAST_UPDATE_FILE) + date = Time.parse(content) rescue nil + end + return date +end + def update_required? - return true unless File.exist?(LAST_UPDATE_FILE) - content = File.read(LAST_UPDATE_FILE) - date = Time.parse(content) rescue Time.parse("2000-01-01") + date = last_update() or Time.parse('2000-01-01') return date < 5.days.ago end