Skip to content

Instantly share code, notes, and snippets.

@ejuher
Last active August 29, 2015 14:14
Show Gist options
  • Save ejuher/3f4c637b419020081404 to your computer and use it in GitHub Desktop.
Save ejuher/3f4c637b419020081404 to your computer and use it in GitHub Desktop.
schema_path = [0, 1, 2].map do |n|
File.join("prod-backup", "schemas", (Time.current - n.days).strftime("%Y_%m_%d"))
end.select do |filepath|
File.exist? File.join(File::SEPARATOR, "Volumes", filepath)
end.first || "file not found"
# changed to:
n = 0; schema_path = "file not found";
while n < 3 && schema_path == "file not found" do
filepath = File.join("prod-backup", "schemas", (Time.current - n.days).strftime("%Y_%m_%d"))
schema_path = filepath if File.exist? File.join(File::SEPARATOR, "Volumes", filepath)
n += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment