Browse Source

BikeCsvImporter: colorize importer output to highlight individual row statuses

master
Ilya Konanykhin 8 years ago
parent
commit
ae79a34652
  1. 1
      Gemfile
  2. 2
      Gemfile.lock
  3. 4
      app/models/bike_csv_importer.rb

1
Gemfile

@ -35,6 +35,7 @@ group :development, :test do
gem 'factory_girl_rails', '~> 1.2'
gem 'pry', '~> 0.9.8'
gem 'faker', '~> 1.2.0'
gem 'colorize'
end
group :test do

2
Gemfile.lock

@ -69,6 +69,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.10.0)
colorize (0.8.1)
database_cleaner (1.2.0)
decent_exposure (1.0.2)
devise (2.0.6)
@ -255,6 +256,7 @@ DEPENDENCIES
cancan
capybara (~> 2.2.1)
coffee-rails (~> 3.2.1)
colorize
database_cleaner (~> 1.2.0)
decent_exposure (~> 1.0.1)
devise (~> 2.0.4)

4
app/models/bike_csv_importer.rb

@ -30,10 +30,10 @@ class BikeCsvImporter
bike = new_bike bike_hash
check_method = dry_run ? :valid? : :save
if bike.try check_method
puts "Imported #{bike.shop_id}: #{bike}"
puts "Imported #{bike.shop_id}: #{bike}".green
imported_count += 1
else
puts "Skipped #{bike.try(:shop_id) || bike_hash.values.first}: #{bike.try(:errors).try(:full_messages).try :join, '; '}"
puts "Skipped #{bike.try(:shop_id) || bike_hash.values.first}: #{bike.try(:errors).try(:full_messages).try :join, '; '}".red
skipped_count += 1
end
end

Loading…
Cancel
Save