Skip to content

Instantly share code, notes, and snippets.

@mrkplt
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkplt/b4b3b8ffe5ed589e5992 to your computer and use it in GitHub Desktop.
Save mrkplt/b4b3b8ffe5ed589e5992 to your computer and use it in GitHub Desktop.
Environment check for safer rake tasks.
module EnvironmentCheck
MESSAGE = "This action is destructive. Proceed?"
def self.execute(message = MESSAGE)
return command_line_output unless inquiry(message) == 'y'
yield if block_given?
end
private
def self.command_line_output
STDOUT.puts "Cool."
end
def self.inquiry(message)
return 'y' unless ::Rails.env.staging? || ::Rails.env.production?
STDOUT.puts "#{message} (y/n)"
STDIN.gets.strip.downcase
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment