Class: MethodLog::Commit
- Inherits:
-
Object
- Object
- MethodLog::Commit
- Defined in:
- lib/method_log/commit.rb
Instance Attribute Summary collapse
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add(source_file) ⇒ Object
- #apply(options = {}) ⇒ Object
- #author ⇒ Object
- #contains?(source_file) ⇒ Boolean
- #find(method_identifier, last_source_file = nil) ⇒ Object
- #hash ⇒ Object
-
#initialize(sha, repository = nil) ⇒ Commit
constructor
A new instance of Commit.
- #message ⇒ Object
- #source_files ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sha, repository = nil) ⇒ Commit
Returns a new instance of Commit.
9 10 11 12 13 |
# File 'lib/method_log/commit.rb', line 9 def initialize(sha, repository = nil) @repository = repository @sha = sha @index = Rugged::Index.new end |
Instance Attribute Details
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
7 8 9 |
# File 'lib/method_log/commit.rb', line 7 def sha @sha end |
Instance Method Details
#==(other) ⇒ Object
61 62 63 |
# File 'lib/method_log/commit.rb', line 61 def ==(other) sha == other.sha end |
#add(source_file) ⇒ Object
15 16 17 18 |
# File 'lib/method_log/commit.rb', line 15 def add(source_file) oid = @repository.write(source_file.source, :blob) @index.add(path: source_file.path, oid: oid, mode: 0100644) end |
#apply(options = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/method_log/commit.rb', line 20 def apply( = {}) user, = [:user], [: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: ) end |
#author ⇒ Object
53 54 55 |
# File 'lib/method_log/commit.rb', line 53 def commit. end |
#contains?(source_file) ⇒ Boolean
38 39 40 |
# File 'lib/method_log/commit.rb', line 38 def contains?(source_file) source_files_by_path[source_file.path] == source_file end |
#find(method_identifier, last_source_file = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/method_log/commit.rb', line 42 def find(method_identifier, last_source_file = nil) method_definition = nil method_name = method_identifier.split(Regexp.union('#', '.')).last source_files.sort_by { |sf| last_source_file == sf ? 1 : 0 }.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 |
#hash ⇒ Object
65 66 67 |
# File 'lib/method_log/commit.rb', line 65 def hash sha.hash end |
#message ⇒ Object
57 58 59 |
# File 'lib/method_log/commit.rb', line 57 def commit. end |
#source_files ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/method_log/commit.rb', line 27 def source_files @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 end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/method_log/commit.rb', line 69 def to_s sha end |