lib/method_log/commit.rb in method_log-0.0.4 vs lib/method_log/commit.rb in method_log-0.0.5

- old
+ new

@@ -22,21 +22,24 @@ parents = @repository.empty? ? [] : [@repository.head.target].compact @sha = Rugged::Commit.create(@repository, tree: tree, parents: parents, update_ref: 'HEAD', author: user, committer: user, message: message) end def source_files - source_files = [] - commit.tree.walk_blobs do |root, blob_hash| - name = blob_hash[:name] - next unless File.extname(name) == '.rb' - path = root.empty? ? name : File.join(root, name) - source = @repository.lookup(blob_hash[:oid]).text - source_files << SourceFile.new(path: path, source: source) + @source_files ||= Enumerator.new do |yielder| + commit.tree.walk_blobs do |root, blob_hash| + name = blob_hash[:name] + next unless File.extname(name) == '.rb' + path = root.empty? ? name : File.join(root, name) + yielder << SourceFile.new(path: path, repository: @repository, sha: blob_hash[:oid]) + end end - source_files end + def contains?(source_file) + source_files_by_path[source_file.path] == source_file + end + def author commit.author end def message @@ -57,8 +60,15 @@ private def commit @commit ||= @repository.lookup(sha) + end + + def source_files_by_path + source_files.inject({}) do |hash, source_file| + hash[source_file.path] = source_file + hash + end end end end \ No newline at end of file