Method: Match::Importer#ensure_valid_file_path

Defined in:
match/lib/match/importer.rb

#ensure_valid_file_path(file_path, file_description, file_extension, optional: false) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'match/lib/match/importer.rb', line 129

def ensure_valid_file_path(file_path, file_description, file_extension, optional: false)
  optional_file_message = optional ? " or leave empty to skip this file" : ""
  file_path ||= UI.input("#{file_description} (#{file_extension}) path#{optional_file_message}:")

  file_path = File.absolute_path(file_path) unless file_path == ""
  file_path = File.exist?(file_path) ? file_path : nil
  UI.user_error!("#{file_description} does not exist at path: #{file_path}") unless !file_path.nil? || optional
  file_path
end