Class: Hexlet::MemberCLI
Constant Summary
Constants inherited
from BaseCLI
BaseCLI::CONFIG_DIR, BaseCLI::CREDENTIALS_FILE
Instance Method Summary
collapse
Methods inherited from BaseCLI
#login
Instance Method Details
#fetch(lesson_slug, exercise_slug) ⇒ Object
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
|
#submit(path) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/hexlet/member_cli.rb', line 4
def submit(path)
expanded_path = File.expand_path(path)
lesson_path, exercise_folder_name = File.split(expanded_path)
lesson_folder_name = File.split(lesson_path)[1]
parts = lesson_folder_name.split("_")
if parts[-1] != "lesson"
puts (t "wrong_lesson_folder")
return false
end
lesson_slug = parts[0, parts.size - 1].join("_")
_, e, s = Open3.capture3("make test -C #{path}")
if s == 0
client = build_client
result = client.submit lesson_slug, exercise_folder_name
if result
puts (t :created)
true
else
puts (t :error)
false
end
else
puts (t :bad_tests)
puts e
false
end
end
|