lib/method_log/commit.rb in method_log-0.0.5 vs lib/method_log/commit.rb in method_log-0.0.6
- old
+ new
@@ -4,22 +4,23 @@
module MethodLog
class Commit
attr_reader :sha
- def initialize(repository: nil, sha: nil)
+ def initialize(sha, repository = nil)
@repository = repository
@sha = sha
@index = Rugged::Index.new
end
def add(source_file)
oid = @repository.write(source_file.source, :blob)
@index.add(path: source_file.path, oid: oid, mode: 0100644)
end
- def apply(user: { email: 'test@example.com', name: 'test', time: Time.now }, message: 'commit-message')
+ def apply(options = {})
+ user, message = options[:user], options[:message]
tree = @index.write_tree(@repository)
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
@@ -34,9 +35,20 @@
end
end
def contains?(source_file)
source_files_by_path[source_file.path] == source_file
+ end
+
+ def find(method_identifier)
+ method_definition = nil
+ method_name = method_identifier.split(Regexp.union('#', '.')).last
+ source_files.each do |source_file|
+ next unless source_file.source[Regexp.new(method_name)]
+ method_finder = MethodFinder.new(source_file)
+ break if method_definition = method_finder.find(method_identifier)
+ end
+ method_definition
end
def author
commit.author
end
\ No newline at end of file