Class: GitQueue::Storage
- Inherits:
-
Object
- Object
- GitQueue::Storage
- Defined in:
- lib/git_queue/storage.rb
Overview
Backend storage
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #history(size = nil) ⇒ Object
-
#initialize(path) ⇒ Storage
constructor
A new instance of Storage.
- #load_queue ⇒ Object
- #store_queue(queue, message) ⇒ Object
Constructor Details
#initialize(path) ⇒ Storage
Returns a new instance of Storage.
14 15 16 |
# File 'lib/git_queue/storage.rb', line 14 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/git_queue/storage.rb', line 8 def path @path end |
Class Method Details
.create(path) ⇒ Object
10 11 12 |
# File 'lib/git_queue/storage.rb', line 10 def self.create(path) Rugged::Repository.init_at(path) end |
Instance Method Details
#history(size = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# 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. end walker.reset histories end |
#load_queue ⇒ Object
18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/git_queue/storage.rb', line 24 def store_queue(queue, ) 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: , committer: , parents: parents, update_ref: 'HEAD', message: ) load_queue end |