class GitQueue::Storage
Backend storage
Attributes
path[R]
Public Class Methods
create(path)
click to toggle source
# File lib/git_queue/storage.rb, line 10 def self.create(path) Rugged::Repository.init_at(path) end
new(path)
click to toggle source
# File lib/git_queue/storage.rb, line 14 def initialize(path) @path = path end
Public Instance Methods
history(size = nil)
click to toggle source
# File lib/git_queue/storage.rb, line 40 def history(size = nil) walker = Rugged::Walker.new(driver) walker.push(driver.head.target.oid) histories = [] walker.each_with_index do |commit, index| break if size && index > size - 1 histories << commit.message end walker.reset histories end
load_queue()
click to toggle source
# File lib/git_queue/storage.rb, line 18 def load_queue return [] if driver.empty? sha = driver.head.target.tree.get_entry(QUEUE_FILE_NAME)[:oid] driver.lookup(sha).content.force_encoding("UTF-8").split("\n") end
store_queue(queue, message)
click to toggle source
# File lib/git_queue/storage.rb, line 24 def store_queue(queue, message) oid = driver.write(queue.join("\n"), :blob) index = driver.index index.add( path: QUEUE_FILE_NAME, oid: oid, mode: 0100644) Rugged::Commit.create( driver, tree: index.write_tree(driver), author: author, committer: author, parents: parents, update_ref: 'HEAD', message: message ) load_queue end
Private Instance Methods
driver()
click to toggle source
# File lib/git_queue/storage.rb, line 54 def driver @driver ||= init_driver end
init_driver()
click to toggle source
# File lib/git_queue/storage.rb, line 58 def init_driver Rugged::Repository.new(path) end
parents()
click to toggle source
# File lib/git_queue/storage.rb, line 66 def parents driver.empty? ? [] : [driver.head.target].compact end