Module: Lockbox::ActiveStorageExtensions::Attachment

Extended by:
ActiveSupport::Concern
Defined in:
lib/lockbox/active_storage_extensions.rb

Instance Method Summary collapse

Instance Method Details

#downloadObject



93
94
95
96
97
98
99
100
101
102
# File 'lib/lockbox/active_storage_extensions.rb', line 93

def download
  result = super

  options = Utils.encrypted_options(record, name)
  if options
    result = Utils.decrypt_result(record, name, options, result)
  end

  result
end

#mark_analyzedObject



124
125
126
127
128
# File 'lib/lockbox/active_storage_extensions.rb', line 124

def mark_analyzed
  if Utils.encrypted_options(record, name)
    blob.update!(metadata: blob..merge(analyzed: true))
  end
end

#open(**options) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/lockbox/active_storage_extensions.rb', line 105

def open(**options)
  blob.open(**options) do |file|
    options = Utils.encrypted_options(record, name)
    if options
      result = Utils.decrypt_result(record, name, options, file.read)
      file.rewind
      # truncate may not be available on all platforms
      # according to the Ruby docs
      # may need to create a new temp file instead
      file.truncate(0)
      file.write(result)
      file.rewind
    end

    yield file
  end
end