Class: Backline::Transaction
- Inherits:
-
Object
- Object
- Backline::Transaction
- Defined in:
- lib/backline/transaction.rb
Instance Method Summary collapse
- #changes? ⇒ Boolean
- #commit(message, options = {}) ⇒ Object
- #delete(model) ⇒ Object
-
#initialize(repository) ⇒ Transaction
constructor
A new instance of Transaction.
- #rollback ⇒ Object
- #save(model) ⇒ Object
Constructor Details
#initialize(repository) ⇒ Transaction
Returns a new instance of Transaction.
3 4 5 6 7 8 9 |
# 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 |
Instance Method Details
#changes? ⇒ Boolean
40 41 42 |
# File 'lib/backline/transaction.rb', line 40 def changes? git.empty? || @index.diff(tree).size > 0 end |
#commit(message, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/backline/transaction.rb', line 25 def commit(, = {}) = .merge({ tree: index.write_tree(git), message: , parents: git.empty? ? [] : [git.head.target].compact, update_ref: 'HEAD' }) Rugged::Commit.create(git, ) if changes? end |
#delete(model) ⇒ Object
21 22 23 |
# File 'lib/backline/transaction.rb', line 21 def delete(model) index.remove(repository.path_for(model)) end |
#rollback ⇒ Object
36 37 38 |
# File 'lib/backline/transaction.rb', line 36 def rollback @index.reload end |
#save(model) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# 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 |