Class: Stash

Inherits:
Thor
  • Object
show all
Defined in:
lib/exercism/cli/stash.rb

Instance Method Summary collapse

Instance Method Details

#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

#listObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/exercism/cli/stash.rb', line 41

def list
  require 'exercism'
  begin
    stashed = Exercism::Api.new(options[:host], Exercism.user).list_stash('user/assignments/stash/list')
    stashed.each do |name|
      puts name
    end
  rescue Exception => e
    puts "Error: unable to retrieve stashed file list"
  end
end

#save(file) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/exercism/cli/stash.rb', line 5

def save(file)
  require 'exercism'

  begin
    puts file
    puts File.read file
    response = Exercism::Api.new(options[:host], Exercism.user).save_stash('user/assignments/stash', file)
    say "Stash file has been saved"
  rescue Exception => e
    puts "Error submitting stash"
    puts e.message
  end
end