Class: MethodLog::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/method_log/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

Returns a new instance of Repository.



7
8
9
10
# File 'lib/method_log/repository.rb', line 7

def initialize(path)
  @repository = Rugged::Repository.new(path)
  @commits = []
end

Instance Method Details

#build_commit(sha = nil) ⇒ Object



12
13
14
# File 'lib/method_log/repository.rb', line 12

def build_commit(sha = nil)
  Commit.new(sha, @repository)
end

#commit(*source_files) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/method_log/repository.rb', line 16

def commit(*source_files)
  options = source_files.pop if source_files.last.is_a?(Hash)
  options ||= {}
  options = { user: { email: '[email protected]', name: 'test', time: Time.now }, message: 'commit-message' }.merge(options)
  build_commit.tap do |commit|
    source_files.each { |sf| commit.add(sf) }
    commit.apply(options)
    @commits << commit
  end
end

#commits(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/method_log/repository.rb', line 27

def commits(options = {})
  Enumerator.new do |yielder|
    if @repository.ref('refs/heads/master')
      @repository.walk(@repository.last_commit).with_index do |commit, index|
        break if options[:max_count] && index >= options[:max_count] - 1
        yielder << build_commit(commit.oid)
      end
    end
  end
end