Class: MethodLog::Repository
- Inherits:
-
Object
- Object
- MethodLog::Repository
- Defined in:
- lib/method_log/repository.rb
Instance Method Summary collapse
- #build_commit(sha = nil) ⇒ Object
- #commit(*source_files) ⇒ Object
- #commits(options = {}) ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
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) = source_files.pop if source_files.last.is_a?(Hash) ||= {} = { user: { email: '[email protected]', name: 'test', time: Time.now }, message: 'commit-message' }.merge() build_commit.tap do |commit| source_files.each { |sf| commit.add(sf) } commit.apply() @commits << commit end end |
#commits(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/method_log/repository.rb', line 27 def commits( = {}) [:sorting] ||= Rugged::SORT_TOPO Enumerator.new do |yielder| if @repository.ref('refs/heads/master') @repository.walk(@repository.last_commit, [:sorting]).with_index do |commit, index| break if [:max_count] && index >= [:max_count] - 1 yielder << build_commit(commit.oid) end end end end |