Class: ActiveStorageValidations::ASVAttachableAdapter::HashIo

Inherits:
Base
  • Object
show all
Defined in:
lib/active_storage_validations/asv_attachable_adapter.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ActiveStorageValidations::ASVAttachableAdapter::Base

Instance Method Details

#content_typeObject



151
152
153
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 151

def content_type
  @attachable[:content_type]
end

#filenameObject



155
156
157
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 155

def filename
  @attachable[:filename]
end

#read(max_byte_size: nil) ⇒ Object



159
160
161
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 159

def read(max_byte_size: nil)
  read_from(@attachable[:io], max_byte_size)
end

#rewindObject



163
164
165
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 163

def rewind
  @attachable[:io].rewind
end

#with_media_path(tempfile, &block) ⇒ Object



167
168
169
170
171
172
173
174
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 167

def with_media_path(tempfile, &block)
  io = @attachable[:io]
  if io.is_a?(StringIO)
    copy_to_tempfile(tempfile, io, &block)
  else
    File.open(io) { |file| yield file.path }
  end
end