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.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/relaxo/directory.rb', line 10

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



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

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

#each(&block) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/relaxo/directory.rb', line 36

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



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

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

#entriesObject



32
33
34
# File 'lib/relaxo/directory.rb', line 32

def entries
	@entries ||= load_entries!
end

#freezeObject



26
27
28
29
30
# File 'lib/relaxo/directory.rb', line 26

def freeze
	@changes.freeze
	
	super
end

#insert(entry) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/relaxo/directory.rb', line 52

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