38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/hexlet/member_cli.rb', line 38
def fetch(lesson_slug, exercise_slug)
client = build_client
if content = client.fetch(lesson_slug, exercise_slug)
lesson_path = File.join("/", "vagrant", "exercises", "#{lesson_slug}_lesson")
exercise_path = File.join(lesson_path, exercise_slug)
if Dir.exists?(exercise_path)
unless yes?(t "ask.replace_exercise")
return true
end
end
FileUtils.mkdir_p(exercise_path)
tarball_path = File.join(exercise_path, "exercise.tar.gz")
File.open(tarball_path, "w") do |f|
f.write content
end
unless ENV['TEST']
tgz = Zlib::GzipReader.new(File.open(tarball_path, 'rb'))
Archive::Tar::Minitar.unpack(tgz, exercise_path)
end
puts (t :ok)
true
else
puts (t :not_found)
false
end
end
|