class Relaxo::Directory
Public Class Methods
new(repository, root_tree, path)
click to toggle source
# File lib/relaxo/directory.rb, line 25 def initialize(repository, root_tree, path) @repository = repository # The root tree, which path is relative to: @root_tree = root_tree # The entry and tree for the directory itself: @entry = nil @tree = nil @path = path @entries = nil @changes = {} end
Public Instance Methods
delete(entry)
click to toggle source
# File lib/relaxo/directory.rb, line 76 def delete(entry) _, _, name = entry[:name].rpartition('/') @changes[name] = nil # Blow away the cache: @entries = nil end
each() { |entry, entry| ... }
click to toggle source
# File lib/relaxo/directory.rb, line 51 def each(&block) return to_enum(:each) unless block_given? entries.each do |entry| entry[:object] ||= @repository.read(entry[:oid]) yield entry[:name], entry[:object] end end
each_entry(&block)
click to toggle source
# File lib/relaxo/directory.rb, line 61 def each_entry(&block) return to_enum(:each_entry) unless block_given? entries.each(&block) end
entries()
click to toggle source
# File lib/relaxo/directory.rb, line 47 def entries @entries ||= load_entries! end
freeze()
click to toggle source
Calls superclass method
# File lib/relaxo/directory.rb, line 41 def freeze @changes.freeze super end
insert(entry)
click to toggle source
# File lib/relaxo/directory.rb, line 67 def insert(entry) _, _, name = entry[:name].rpartition('/') @changes[name] = entry # Blow away the cache: @entries = nil end
Private Instance Methods
fetch_entry()
click to toggle source
Look up the entry for the given directory `@path`:
# File lib/relaxo/directory.rb, line 88 def fetch_entry @entry ||= @root_tree.path(@path) end
fetch_tree()
click to toggle source
Load the directory tree for the given `@path`:
# File lib/relaxo/directory.rb, line 93 def fetch_tree @tree ||= Rugged::Tree.new(@repository, fetch_entry[:oid]) rescue Rugged::TreeError return nil end
load_entries!()
click to toggle source
Load the entries from the tree, applying any changes.
# File lib/relaxo/directory.rb, line 100 def load_entries! entries = @changes.dup if tree = fetch_tree tree.each_blob do |entry| unless entries.key? entry[:name] entries[entry[:name]] = entry end end end return entries.values.compact.sort_by{|entry| entry[:name]} end