Method: Stash#apply

Defined in:
lib/exercism/cli/stash.rb

#apply(file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/exercism/cli/stash.rb', line 21

def apply(file)
  require 'exercism'

  begin
    stash = Exercism::Api.new(options[:host], Exercism.user).apply_stash('user/assignments/stash', file)
    if File.exists?(stash.filename)
      say "File: " + stash.filename + " already exists"
      if no?("Overwrite it? [y/n]")
        return
      end
    end
    stash.save
    puts "Stash file downloaded successfully: " + File.join(FileUtils.pwd, stash.filename)
  rescue Exception => e
    puts "Error: No stash file was found."
  end
end