forked from michaelfeathers/repodepot-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_history.rb
More file actions
43 lines (31 loc) · 758 Bytes
/
Copy pathcode_history.rb
File metadata and controls
43 lines (31 loc) · 758 Bytes
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
module RepoDepot
class CodeHistory
attr_reader :name, :events
def initialize name, events
@name = name
@events = events
end
def commits
@commits ||= events.map { |e| [e.commit, e.date]}.uniq
end
def commit sha1
Commit.new(sha1, state_at_commit(sha1))
end
def for_commit sha1
Repository.new(sha1, events.group_by(&:commit)[sha1])
end
def state_at_commit sha1
events.group_by(&:commit)[sha1]
end
protected
def collection_of symbol, class_object
events.group_by(&symbol).map { |args| class_object.new(*args) }
end
def complexity_of collection
collection.map(&:complexity).reduce(0.0, :+)
end
def to_s
@name
end
end
end