Instantly share code, notes, and snippets.

Embed
What would you like to do?
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