Class: Relaxo::Dataset

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

Direct Known Subclasses

Changeset

Instance Method Summary collapse

Constructor Details

#initialize(repository, tree) ⇒ Dataset

Returns a new instance of Dataset.



27
28
29
30
31
32
# File 'lib/relaxo/dataset.rb', line 27

def initialize(repository, tree)
	@repository = repository
	@tree = tree
	
	@directories = {}
end

Instance Method Details

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/relaxo/dataset.rb', line 52

def directory?(path)
	@directories.key?(path) or @tree.path(path)[:type] == :tree
rescue Rugged::TreeError
	return false
end

#each(path = '', &block) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/relaxo/dataset.rb', line 58

def each(path = '', &block)
	return to_enum(:each, path) unless block_given?
	
	directory = fetch_directory(path)
	
	directory.each(&block)
end

#exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/relaxo/dataset.rb', line 48

def exist?(path)
	read(path) or directory?(path)
end

#file?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/relaxo/dataset.rb', line 44

def file?
	read(path)
end

#read(path) ⇒ Object Also known as: []



34
35
36
37
38
39
40
# File 'lib/relaxo/dataset.rb', line 34

def read(path)
	if entry = @tree.path(path) and entry[:type] == :blob and oid = entry[:oid]
		@repository.read(oid)
	end
rescue Rugged::TreeError
	return nil
end