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.



79
80
81
82
# File 'lib/valkyrie/storage/disk.rb', line 79

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

Class Method Details

.open(path, mode) ⇒ Object



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

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_file ⇒ Object



84
85
86
# File 'lib/valkyrie/storage/disk.rb', line 84

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