instance method open_local_io

Ruby on Rails edge

Since edge Private — implementation detail, not part of the public API

Signature

open_local_io(tmpdir:)

Opens a local io for reading, yielding a file-like object. If the io is already a File with a path, yield it directly. Otherwise, copy to a tempfile first since analyzers need file paths.

Parameters

tmpdir keyreq
Source
# File activestorage/app/models/active_storage/blob.rb, line 404
    def open_local_io(tmpdir:)
      if local_io.respond_to?(:path) && local_io.path && File.exist?(local_io.path)
        local_io.rewind if local_io.respond_to?(:rewind)
        yield local_io
      else
        Tempfile.open([ "ActiveStorage-#{id}-", filename.extension_with_delimiter ], tmpdir) do |file|
          file.binmode
          local_io.rewind if local_io.respond_to?(:rewind)
          IO.copy_stream(local_io, file)
          local_io.rewind if local_io.respond_to?(:rewind)
          file.rewind
          yield file
        end
      end
    end

Defined in activestorage/app/models/active_storage/blob.rb line 404 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::Blob

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close