module EchoUploads::TmpFileWriting::ClassMethods

Public Instance Methods

echo_uploads_configure_tmp_file_writing(attr, options) click to toggle source
# File lib/echo_uploads/tmp_file_writing.rb, line 124
def echo_uploads_configure_tmp_file_writing(attr, options)
  if options[:write_tmp_file] == :after_rollback
    # Because ActiveRecord rolls back the transaction on validation failure, we
    # can't just use a convenient after_validation callback. Nor can we use an
    # after_rollback hook, because that causes all kinds of bizarre side-effects,
    # especially in the test environment.
    self.echo_uploads_save_wrapper += [[attr, options]]
  elsif options[:write_tmp_file] == :after_validation
    after_validation do
      echo_uploads_maybe_write_tmp_file(attr, options) { errors.empty? }
    end
  end
end