Class: Ark::Repo
- Inherits:
-
Object
- Object
- Ark::Repo
- Defined in:
- lib/ark/repo.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear(message = nil) ⇒ Object
- #delete(key, message = nil) ⇒ Object
- #get(key, value = nil) ⇒ Object
- #git ⇒ Object
-
#initialize(options = {}) ⇒ Repo
constructor
A new instance of Repo.
- #inspect ⇒ Object
- #keys ⇒ Object
- #log(key) ⇒ Object
- #set(key, value, message = nil) ⇒ Object
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 = ::Grit::Repo.(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 |
.db ⇒ Object
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( = nil) # This is not working. Need to investigate ||= "purged repo" save() 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, = nil, *) ||= "deleted '#{key}'" self.get(key).tap do save() {|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 |
#git ⇒ Object
69 70 71 |
# File 'lib/ark/repo.rb', line 69 def git @git ||= ::Grit::Repo.new(path) end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/ark/repo.rb', line 73 def inspect %Q{#<Ark::Repo "path=#{path}">} end |
#keys ⇒ Object
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, = nil) ||= "set '#{key}'" save() do |index| index.add(key, value) true end end |