Last active
August 29, 2015 14:22
-
-
Save mrkplt/b4b3b8ffe5ed589e5992 to your computer and use it in GitHub Desktop.
Environment check for safer rake tasks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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