Class: Valkyrie::Storage::Disk::LazyFile

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/storage/disk.rb

Overview

LazyFile takes File.open parameters but doesn’t leave a file handle open on instantiation. This way StorageAdapter#find_by doesn’t open a handle silently and never clean up after itself.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, mode) ⇒ LazyFile

Returns a new instance of LazyFile.



57
58
59
60
# File 'lib/valkyrie/storage/disk.rb', line 57

def initialize(path, mode)
  @__path = path
  @__mode = mode
end

Class Method Details

.open(path, mode) ⇒ Object



48
49
50
51
52
53
# File 'lib/valkyrie/storage/disk.rb', line 48

def self.open(path, mode)
  # Open the file regularly and close it, so it can error if it doesn't
  # exist.
  File.open(path, mode).close
  new(path, mode)
end

Instance Method Details

#_inner_fileObject



62
63
64
# File 'lib/valkyrie/storage/disk.rb', line 62

def _inner_file
  @_inner_file ||= File.open(@__path, @__mode)
end