Class: Ark::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/ark/repo.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Repo

Returns a new instance of Repo.



18
19
20
21
# File 'lib/ark/repo.rb', line 18

def initialize(options = {})
  @options = options
  ::Grit::Repo.init_bare_or_open(path)
end

Class Method Details

.connect(path = '/tmp/ark.git') ⇒ Object



13
14
15
# File 'lib/ark/repo.rb', line 13

def connect(path='/tmp/ark.git')
  self.db = self.new(:repo => path)
end

.dbObject



9
10
11
# File 'lib/ark/repo.rb', line 9

def db
  @db
end

.db=(db) ⇒ Object



5
6
7
# File 'lib/ark/repo.rb', line 5

def db=(db)
  @db = db
end

Instance Method Details

#clear(message = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ark/repo.rb', line 44

def clear(message = nil)
  # This is not working. Need to investigate
  message ||= "purged repo"
  save(message) do |index|
    if tree = index.current_tree
      tree.contents.each do |entry|
        index.delete(entry.name)
      end
    end
  end
end

#delete(key, message = nil) ⇒ Object



37
38
39
40
41
42
# File 'lib/ark/repo.rb', line 37

def delete(key, message = nil, *)
  message ||= "deleted '#{key}'"
  self.get(key).tap do
    save(message) {|index| index.delete(key) }
  end
end

#get(key, value = nil) ⇒ Object



31
32
33
34
35
# File 'lib/ark/repo.rb', line 31

def get(key, value = nil, *)
  if head && blob = head.commit.tree / key
    blob.data
  end
end

#gitObject



69
70
71
# File 'lib/ark/repo.rb', line 69

def git
  @git ||= ::Grit::Repo.new(path)
end

#inspectObject



73
74
75
# File 'lib/ark/repo.rb', line 73

def inspect
  %Q{#<Ark::Repo "path=#{path}">}
end

#keysObject



60
61
62
63
64
65
66
67
# File 'lib/ark/repo.rb', line 60

def keys
  begin
    head.commit.tree.contents.map {|blob| blob.name }
  rescue NoMethodError
    # Repo isn't populated yet
    []
  end
end

#log(key) ⇒ Object



56
57
58
# File 'lib/ark/repo.rb', line 56

def log(key)
  git.log(branch, key).map{|commit| commit.to_hash }
end

#set(key, value, message = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/ark/repo.rb', line 23

def set(key, value, message = nil)
  message ||= "set '#{key}'"
  save(message) do |index|
    index.add(key, value)
    true
  end
end