Permalink
Browse files

added source_file collection to repository

  • Loading branch information...
1 parent 6ed52f0 commit 60a4feb0d042870bcbfd5eb2415ad410525d7369 @michaelfeathers michaelfeathers committed May 14, 2011
Showing with 28 additions and 1 deletion.
  1. +9 −1 repository.rb
  2. +12 −0 repository_spec.rb
  3. +7 −0 sourcefile.rb
View
@@ -1,16 +1,24 @@
+require_relative 'class.rb'
+require_relative 'sourcefile.rb'
+
+# MF remove duplication in initialize
+
module RepoDepot
class Repository
- attr_reader :classes
+ attr_reader :classes, :source_files
def initialize name, events
@events = events
@classes = events.group_by {|e| e.class_name }
.map { |name, events| Class.new(name, events) }
+ @source_files = events.group_by {|e| e.file_name }
+ .map { |name, events| SourceFile.new(name, events) }
end
def commits
@commits ||= @events.map { |e| e.commit }
end
+
end
end
View
@@ -22,7 +22,19 @@
it "should create a list of commits for events" do
events = [CodeEvent.new(commit: '9e9273dcbbc7bcc882520f2a8ffe13e4f3b273ac'),
CodeEvent.new(commit: 'e9c1c0adb4e92d4b2c4117dbc139821ccf2b2851')]
+ RepoDepot::Repository.new('', events).commits.count == 2
+ end
+ it "should not populate files when not given events" do
+ repository = RepoDepot::Repository.new('', [])
+ repository.source_files.should be_empty
+ end
+ it "should add a file when there is an event for a file" do
+ event = CodeEvent.new(file_name: "A")
+ repository = RepoDepot::Repository.new('', [event])
+ repository.source_files.count.should == 1
end
+
+
end
View
@@ -0,0 +1,7 @@
+
+module RepoDepot
+ class SourceFile
+ def initialize name, events
+ end
+ end
+end

0 comments on commit 60a4feb

Please sign in to comment.