Class: Relaxo::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/relaxo/directory.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository, root_tree, path) ⇒ Directory

Returns a new instance of Directory.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Method Details

#delete(entry) ⇒ Object



76
77
78
79
80
81
82
83
# 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(&block) ⇒ Object



51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



61
62
63
64
65
# File 'lib/relaxo/directory.rb', line 61

def each_entry(&block)
	return to_enum(:each_entry) unless block_given?
	
	entries.each(&block)
end

#entriesObject



47
48
49
# File 'lib/relaxo/directory.rb', line 47

def entries
	@entries ||= load_entries!
end

#freezeObject



41
42
43
44
45
# File 'lib/relaxo/directory.rb', line 41

def freeze
	@changes.freeze
	
	super
end

#insert(entry) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/relaxo/directory.rb', line 67

def insert(entry)
	_, _, name = entry[:name].rpartition('/')
	
	@changes[name] = entry
	
	# Blow away the cache:
	@entries = nil
end