1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/command/helpers/editor.rb

34 lines
948 B
Ruby
Raw Normal View History

require "active_support/encrypted_file"
module Rails
module Command
module Helpers
module Editor
private
def ensure_editor_available(command:)
if ENV["EDITOR"].to_s.empty?
say "No $EDITOR to open file in. Assign one like this:"
say ""
say %(EDITOR="mate --wait" #{command})
say ""
say "For editors that fork and exit immediately, it's important to pass a wait flag,"
say "otherwise the credentials will be saved immediately with no chance to edit."
false
else
true
end
end
def catch_editing_exceptions
yield
rescue Interrupt
say "Aborted changing file: nothing saved."
rescue ActiveSupport::EncryptedFile::MissingKeyError => error
say error.message
end
end
end
end
end