Class: DocumentDownload
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- DocumentDownload
- Defined in:
- app/models/document_download.rb
Overview
DocumentDownload
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.destroy_all(file) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/models/document_download.rb', line 22 def self.destroy_all(file) logger.debug("CSV Destroy") ::CSV.foreach(file.path, headers: true) do |row| logger.debug("CSV Row: #{row.to_hash}") DocumentDownload.destroy_by(id: row[0], friendlier_id: row[1]) end end |
.import(file) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/models/document_download.rb', line 13 def self.import(file) logger.debug("CSV Import") ::CSV.foreach(file.path, headers: true) do |row| logger.debug("CSV Row: #{row.to_hash}") document_download = DocumentDownload.find_or_initialize_by(friendlier_id: row[0], label: row[1], value: row[2]) document_download.update(row.to_hash) end end |
Instance Method Details
#reindex_document ⇒ Object
34 35 36 |
# File 'app/models/document_download.rb', line 34 def reindex_document document.save end |
#to_csv ⇒ Object
30 31 32 |
# File 'app/models/document_download.rb', line 30 def to_csv attributes.values end |