Class: Backline::Repository
- Inherits:
-
Object
- Object
- Backline::Repository
- Defined in:
- lib/backline/repository.rb
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Class Method Summary collapse
Instance Method Summary collapse
- #all(type) ⇒ Object
- #find(type, path) ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
- #path_for(model) ⇒ Object
- #register(type, path = nil) ⇒ Object
- #transaction(message = "Commit generated using Backline") ⇒ Object
Constructor Details
#initialize(path) ⇒ Repository
18 19 20 21 22 23 |
# File 'lib/backline/repository.rb', line 18 def initialize(path) @git = Rugged::Repository.new(path) yield self if block_given? rescue Rugged::OSError => e raise(Backline::Error, e.) end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
51 52 53 |
# File 'lib/backline/repository.rb', line 51 def git @git end |
Class Method Details
.clone(remote_path, local_path, &block) ⇒ Object
12 13 14 15 16 |
# File 'lib/backline/repository.rb', line 12 def self.clone(remote_path, local_path, &block) Rugged::Repository.clone_at(remote_path, local_path, bare: true) new(local_path, &block) end |
.create(path, &block) ⇒ Object
6 7 8 9 10 |
# File 'lib/backline/repository.rb', line 6 def self.create(path, &block) Rugged::Repository.init_at(path, :bare) new(path, &block) end |
Instance Method Details
#all(type) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/backline/repository.rb', line 35 def all(type) tree = subtree_for(type) tree.enum_for(:each_blob).map do |entry| load_from_entry(type, entry) end end |
#find(type, path) ⇒ Object
29 30 31 32 33 |
# File 'lib/backline/repository.rb', line 29 def find(type, path) tree = subtree_for(type) entry = tree.path(path.to_s) load_from_entry(type, entry) end |
#path_for(model) ⇒ Object
53 54 55 |
# File 'lib/backline/repository.rb', line 53 def path_for(model) "#{mapping[model.class]}/#{model.id}" end |
#register(type, path = nil) ⇒ Object
25 26 27 |
# File 'lib/backline/repository.rb', line 25 def register(type, path = nil) mapping[type] = (path || type.name.underscore).to_s end |
#transaction(message = "Commit generated using Backline") ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/backline/repository.rb', line 42 def transaction( = "Commit generated using Backline") Transaction.new(self).tap do |transaction| if block_given? yield transaction transaction.commit() end end end |