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.



70
71
72
73
# File 'lib/valkyrie/storage/disk.rb', line 70

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

Class Method Details

.open(path, mode) ⇒ Object



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

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



75
76
77
# File 'lib/valkyrie/storage/disk.rb', line 75

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