Sha256: 5c488ee02e86c8759abe56f37429b8f4070632173bf545b6b6e7312dd2eff3f8

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

require 'rugged'

require 'method_log/commit'

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

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

    def commit(*source_files)
      options = source_files.pop if source_files.last.is_a?(Hash)
      options ||= {}
      options = { user: { email: 'test@example.com', 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

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
method_log-0.1.1 lib/method_log/repository.rb
method_log-0.1.0 lib/method_log/repository.rb
method_log-0.0.7 lib/method_log/repository.rb
method_log-0.0.6 lib/method_log/repository.rb