Class: PDFService::Utils::TempfileService

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf_service/utils/tempfile_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(root: Pathname('.')) ⇒ TempfileService

Returns a new instance of TempfileService.



4
5
6
# File 'lib/pdf_service/utils/tempfile_service.rb', line 4

def initialize(root: Pathname('.'))
  @root = Pathname(root)
end

Instance Method Details

#use(name: SecureRandom.hex, extension: 'tmp') ⇒ Object



8
9
10
11
12
13
# File 'lib/pdf_service/utils/tempfile_service.rb', line 8

def use(name: SecureRandom.hex, extension: 'tmp')
  path = Pathname('.').expand_path.join("#{name}.#{extension}")
  yield(path)
ensure
  path.unlink if path.exist?
end