class Backline::Transaction
Attributes
git[R]
index[R]
repository[R]
Public Class Methods
new(repository)
click to toggle source
# File lib/backline/transaction.rb, line 3 def initialize(repository) @repository = repository @git = repository.git @index = git.index index.read_tree(tree) unless git.empty? end
Public Instance Methods
changes?()
click to toggle source
# File lib/backline/transaction.rb, line 40 def changes? git.empty? || @index.diff(tree).size > 0 end
commit(message, options = {})
click to toggle source
# File lib/backline/transaction.rb, line 25 def commit(message, options = {}) options = options.merge({ tree: index.write_tree(git), message: message, parents: git.empty? ? [] : [git.head.target].compact, update_ref: 'HEAD' }) Rugged::Commit.create(git, options) if changes? end
delete(model)
click to toggle source
# File lib/backline/transaction.rb, line 21 def delete(model) index.remove(repository.path_for(model)) end
rollback()
click to toggle source
# File lib/backline/transaction.rb, line 36 def rollback @index.reload end
save(model)
click to toggle source
# File lib/backline/transaction.rb, line 11 def save(model) oid = git.write(model.class.dump(model), :blob) index.add({ path: repository.path_for(model), oid: oid, mode: 0100644 }) end
Private Instance Methods
tree()
click to toggle source
# File lib/backline/transaction.rb, line 48 def tree git.head.target.tree end