/
avatar.rb
79 lines (62 loc) · 1.74 KB
/
avatar.rb
1
2
3
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
36
37
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
69
70
71
72
73
74
75
76
77
78
79
class Avatar
def initialize(kata, name)
# Does *not* validate.
# All access to avatar object must come through
# dojo.katas[id].avatars[name]
@kata = kata
@name = name
end
# modifiers
def test(delta, files, max_seconds)
deleted_filenames = delta[:deleted]
changed_files = {}
delta[:new].each { |filename|
changed_files[filename] = files[filename]
}
delta[:changed].each { |filename|
changed_files[filename] = files[filename]
}
args = []
args << kata.image_name # eg 'cyberdojofoundation/gcc_assert'
args << kata.id # eg 'FE8A79A264'
args << name # eg 'salmon'
args << deleted_filenames # eg [ 'instructions' ]
args << changed_files # eg { 'hiker.h' => ... 'hiker.c' => ... }
args << max_seconds # eg 10
runner.run(*args)
end
def tested(files, at, output, colour)
storer.avatar_ran_tests(kata.id, name, files, at, output, colour)
end
# queries
attr_reader :kata, :name
def parent
kata
end
def active?
# Players sometimes start an extra avatar solely to read the
# instructions. I don't want these avatars appearing on the
# dashboard. When forking a new kata you can enter as one
# animal to sanity check it is ok (but not press [test])
!lights.empty?
end
def tags
increments.map { |h| Tag.new(self, h) }
end
def lights
tags.select(&:light?)
end
def visible_filenames
visible_files.keys
end
def visible_files
storer.avatar_visible_files(kata.id, name)
end
private
def increments
storer.avatar_increments(kata.id, name)
end
include NearestAncestors
def storer; nearest_ancestors(:storer); end
def runner; nearest_ancestors(:runner); end
end