lib/dynamoid/tasks/database.rake in dynamoid-2.2.0 vs lib/dynamoid/tasks/database.rake in dynamoid-3.0.0

- old
+ new

@@ -1,41 +1,41 @@ +# frozen_string_literal: true + require 'dynamoid' require 'dynamoid/tasks/database' namespace :dynamoid do - desc "Creates DynamoDB tables, one for each of your Dynamoid models - does not modify pre-existing tables" - task :create_tables => :environment do + desc 'Creates DynamoDB tables, one for each of your Dynamoid models - does not modify pre-existing tables' + task create_tables: :environment do # Load models so Dynamoid will be able to discover tables expected. - Dir[ File.join(Dynamoid::Config.models_dir, "*.rb") ].sort.each { |file| require file } + Dir[File.join(Dynamoid::Config.models_dir, '*.rb')].sort.each { |file| require file } if Dynamoid.included_models.any? tables = Dynamoid::Tasks::Database.create_tables - result = tables[:created].map{ |c| "#{c} created" } + tables[:existing].map{ |e| "#{e} already exists" } - result.sort.each{ |r| puts r } + result = tables[:created].map { |c| "#{c} created" } + tables[:existing].map { |e| "#{e} already exists" } + result.sort.each { |r| puts r } else - puts "Dynamoid models are not loaded, or you have no Dynamoid models." + puts 'Dynamoid models are not loaded, or you have no Dynamoid models.' end end desc 'Tests if the DynamoDB instance can be contacted using your configuration' - task :ping => :environment do + task ping: :environment do success = false failure_reason = nil begin Dynamoid::Tasks::Database.ping success = true - rescue Exception => e + rescue StandardError => e failure_reason = e.message end msg = "Connection to DynamoDB #{success ? 'OK' : 'FAILED'}" msg << if Dynamoid.config.endpoint " at local endpoint '#{Dynamoid.config.endpoint}'" else ' at remote AWS endpoint' end - if not success - msg << ", reason being '#{failure_reason}'" - end + msg << ", reason being '#{failure_reason}'" unless success puts msg end end