Module: LogStruct::Integrations::CarrierWave::LoggingMethods
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/log_struct/integrations/carrierwave.rb
Overview
Logs the operations that store, delete or fetch a file: store! (an upload, when there's a cached file to store), remove! (a delete) and download! (a remote URL fetched into the cache). retrieve_from_store! isn't logged: it only points the uploader at a stored file, and runs each time a record's mounted file is read.
Instance Method Summary collapse
Instance Method Details
#download!(uri, remote_headers = {}) ⇒ T.untyped
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/log_struct/integrations/carrierwave.rb', line 70 def download!(uri, remote_headers = {}) result = super log_file_operation do Log::CarrierWave::Download.new( **T.unsafe(file_fields), filename: file&.filename, mime_type: file&.content_type, size: file&.size ) end result end |
#remove! ⇒ T.untyped
62 63 64 65 66 67 |
# File 'lib/log_struct/integrations/carrierwave.rb', line 62 def remove! fields = file ? file_fields : nil result = super log_file_operation { Log::CarrierWave::Delete.new(**T.unsafe(fields)) } if fields result end |
#store!(*args) ⇒ T.untyped
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/log_struct/integrations/carrierwave.rb', line 40 def store!(*args) # CarrierWave only stores a cached file; a record's save calls store! on every uploader storing = !cache_only && (cached? || !args.first.nil?) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = super return result unless storing && !cached? duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000.0 log_file_operation do # file_fields is a Hash Sorbet can't check against the struct's keyword arguments Log::CarrierWave::Upload.new( **T.unsafe(file_fields), filename: file&.filename, mime_type: file&.content_type, size: file&.size, duration_ms: duration_ms ) end result end |