Class: Relaxo::Dataset
- Inherits:
-
Object
- Object
- Relaxo::Dataset
- Defined in:
- lib/relaxo/dataset.rb
Direct Known Subclasses
Instance Method Summary collapse
- #directory?(path) ⇒ Boolean
- #each(path = '', &block) ⇒ Object
- #exist?(path) ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(repository, tree) ⇒ Dataset
constructor
A new instance of Dataset.
- #read(path) ⇒ Object (also: #[])
Constructor Details
#initialize(repository, tree) ⇒ Dataset
Returns a new instance of Dataset.
12 13 14 15 16 17 |
# File 'lib/relaxo/dataset.rb', line 12 def initialize(repository, tree) @repository = repository @tree = tree @directories = {} end |
Instance Method Details
#directory?(path) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/relaxo/dataset.rb', line 37 def directory?(path) @directories.key?(path) or @tree.path(path)[:type] == :tree rescue Rugged::TreeError return false end |
#each(path = '', &block) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/relaxo/dataset.rb', line 43 def each(path = '', &block) return to_enum(:each, path) unless block_given? directory = fetch_directory(path) directory.each(&block) end |
#exist?(path) ⇒ Boolean
33 34 35 |
# File 'lib/relaxo/dataset.rb', line 33 def exist?(path) read(path) or directory?(path) end |
#file? ⇒ Boolean
29 30 31 |
# File 'lib/relaxo/dataset.rb', line 29 def file? read(path) end |
#read(path) ⇒ Object Also known as: []
19 20 21 22 23 24 25 |
# File 'lib/relaxo/dataset.rb', line 19 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 |