Skip to main content
deleted 26 characters in body; edited tags
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

So I'm trying to remove the tmp/letter_opener folder. Everything works fine, just wondering if there's a better way to write it. My next step is to write some tests, to double check that I can only accept those inputs (currently failing)

#my_rake_task.rake

namespace :cleanup do

desc 'Deletes the emails inside tmp/letter_opener folder.'
task letter_opener_emails: :environment do

start_time = Time.current
Rails.logger.info "Task starting at #{start_time}."
puts "Task starting at #{start_time}."

print 'About to remove the tmp/letter_opener folder. Press [Nn] to abort. Press [Yy] to continue.'
option = STDIN.gets.strip

case option #[FIXME]: Not deleting the folders
  when /[^Nn]/ then FileUtils.rm_r(Dir.glob('tmp/letter_opener/*'))
    puts 'Directory contents removed'
  when /[^Yy]/ then 'Exiting the task now.' 
    # abort_message
end
end

Thanks in advance

So I'm trying to remove the tmp/letter_opener folder. Everything works fine, just wondering if there's a better way to write it. My next step is to write some tests, to double check that I can only accept those inputs (currently failing)

#my_rake_task.rake

namespace :cleanup do

desc 'Deletes the emails inside tmp/letter_opener folder.'
task letter_opener_emails: :environment do

start_time = Time.current
Rails.logger.info "Task starting at #{start_time}."
puts "Task starting at #{start_time}."

print 'About to remove the tmp/letter_opener folder. Press [Nn] to abort. Press [Yy] to continue.'
option = STDIN.gets.strip

case option #[FIXME]: Not deleting the folders
  when /[^Nn]/ then FileUtils.rm_r(Dir.glob('tmp/letter_opener/*'))
    puts 'Directory contents removed'
  when /[^Yy]/ then 'Exiting the task now.' 
    # abort_message
end
end

Thanks in advance

I'm trying to remove the tmp/letter_opener folder. Everything works fine, just wondering if there's a better way to write it. My next step is to write some tests, to double check that I can only accept those inputs (currently failing)

#my_rake_task.rake

namespace :cleanup do

desc 'Deletes the emails inside tmp/letter_opener folder.'
task letter_opener_emails: :environment do

start_time = Time.current
Rails.logger.info "Task starting at #{start_time}."
puts "Task starting at #{start_time}."

print 'About to remove the tmp/letter_opener folder. Press [Nn] to abort. Press [Yy] to continue.'
option = STDIN.gets.strip

case option #[FIXME]: Not deleting the folders
  when /[^Nn]/ then FileUtils.rm_r(Dir.glob('tmp/letter_opener/*'))
    puts 'Directory contents removed'
  when /[^Yy]/ then 'Exiting the task now.' 
    # abort_message
end
end
Post Migrated Here from stackoverflow.com (revisions)
Source Link
D_S
  • 153
  • 4

Removing folders from my rails app with rake

So I'm trying to remove the tmp/letter_opener folder. Everything works fine, just wondering if there's a better way to write it. My next step is to write some tests, to double check that I can only accept those inputs (currently failing)

#my_rake_task.rake

namespace :cleanup do

desc 'Deletes the emails inside tmp/letter_opener folder.'
task letter_opener_emails: :environment do

start_time = Time.current
Rails.logger.info "Task starting at #{start_time}."
puts "Task starting at #{start_time}."

print 'About to remove the tmp/letter_opener folder. Press [Nn] to abort. Press [Yy] to continue.'
option = STDIN.gets.strip

case option #[FIXME]: Not deleting the folders
  when /[^Nn]/ then FileUtils.rm_r(Dir.glob('tmp/letter_opener/*'))
    puts 'Directory contents removed'
  when /[^Yy]/ then 'Exiting the task now.' 
    # abort_message
end
end

Thanks in advance