class Backline::Repository

Attributes

git[R]

Public Class Methods

clone(remote_path, local_path, &block) click to toggle source
# 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) click to toggle source
# File lib/backline/repository.rb, line 6
def self.create(path, &block)
  Rugged::Repository.init_at(path, :bare)

  new(path, &block)
end
new(path) { |self| ... } click to toggle source
# 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.message)
end

Public Instance Methods

all(type) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/backline/repository.rb, line 53
def path_for(model)
  "#{mapping[model.class]}/#{model.id}"
end
register(type, path = nil) click to toggle source
# 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") { |transaction| ... } click to toggle source
# File lib/backline/repository.rb, line 42
def transaction(message = "Commit generated using Backline")
  Transaction.new(self).tap do |transaction|
    if block_given?
      yield transaction
      transaction.commit(message)
    end
  end
end

Private Instance Methods

load_from_entry(type, entry) click to toggle source
# File lib/backline/repository.rb, line 67
def load_from_entry(type, entry)
  content = git.lookup(entry[:oid]).content
  type.load(content).tap do |model|
    model.id = entry[:name]
  end
end
mapping() click to toggle source
# File lib/backline/repository.rb, line 59
def mapping
  @mapping ||= {}
end
subtree_for(type) click to toggle source
# File lib/backline/repository.rb, line 74
def subtree_for(type)
  oid = tree.path(mapping[type])[:oid]
  git.lookup(oid)
end
tree() click to toggle source
# File lib/backline/repository.rb, line 63
def tree
  git.head.target.tree
end