Class: Ole::Storage::DirClass::Dir

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ole/storage/file_system.rb

Overview

note that there is nothing remotely ole specific about this class. it simply provides the dir like sequential access methods on top of an array.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#group_by, #sum

Constructor Details

#initialize(path, entries) ⇒ Dir

Returns a new instance of Dir.



354
355
356
357
# File 'lib/ole/storage/file_system.rb', line 354

def initialize path, entries
	@path, @entries, @pos = path, entries, 0
	@closed = false
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



353
354
355
# File 'lib/ole/storage/file_system.rb', line 353

def path
  @path
end

Instance Method Details

#closeObject



369
370
371
# File 'lib/ole/storage/file_system.rb', line 369

def close
	@closed = true
end

#each(&block) ⇒ Object

Raises:

  • (IOError)


364
365
366
367
# File 'lib/ole/storage/file_system.rb', line 364

def each(&block)
	raise IOError if @closed
	@entries.each(&block)
end

#posObject Also known as: tell

Raises:

  • (IOError)


359
360
361
362
# File 'lib/ole/storage/file_system.rb', line 359

def pos
	raise IOError if @closed
	@pos
end

#pos=(pos) ⇒ Object Also known as: seek

Raises:

  • (IOError)


380
381
382
383
# File 'lib/ole/storage/file_system.rb', line 380

def pos= pos
	raise IOError if @closed
	@pos = [[0, pos].max, @entries.length].min
end

#readObject



373
374
375
376
377
378
# File 'lib/ole/storage/file_system.rb', line 373

def read
	raise IOError if @closed
	@entries[pos]
ensure
	@pos += 1 if pos < @entries.length
end

#rewindObject



387
388
389
# File 'lib/ole/storage/file_system.rb', line 387

def rewind
	seek 0
end