From 9de85d08145a1025563db4fffb621e6b26c8d4f3 Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Thu, 8 Feb 2018 18:49:45 -0200 Subject: [PATCH] fix: makes sure unique and sequential date --- lib/generators/rating/install_generator.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/generators/rating/install_generator.rb b/lib/generators/rating/install_generator.rb index 33ec15a..e5b3fa3 100644 --- a/lib/generators/rating/install_generator.rb +++ b/lib/generators/rating/install_generator.rb @@ -7,14 +7,18 @@ module Rating desc 'creates Rating migration' def create_migration - template 'db/migrate/create_rating_table.rb', "db/migrate/#{timestamp}_create_rating_table.rb" - template 'db/migrate/create_rate_table.rb', "db/migrate/#{timestamp}_create_rate_table.rb" + template 'db/migrate/create_rating_table.rb', "db/migrate/#{timestamp(0)}_create_rating_table.rb" + template 'db/migrate/create_rate_table.rb', "db/migrate/#{timestamp(1)}_create_rate_table.rb" end private - def timestamp - Time.current.strftime '%Y%m%d%H%M%S' + def time + @time ||= Time.current + end + + def timestamp(seconds) + (time + seconds.seconds).strftime '%Y%m%d%H%M%S' end end end