Class: DocumentAccess
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- DocumentAccess
- Defined in:
- app/models/document_access.rb
Overview
DocumentAccess
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.destroy_all(file) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/models/document_access.rb', line 23 def self.destroy_all(file) logger.debug("CSV Destroy") ::CSV.foreach(file.path, headers: true) do |row| logger.debug("CSV Row: #{row.to_hash}") DocumentAccess.destroy_by(id: row[0], friendlier_id: row[1]) end true end |
.import(file) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/models/document_access.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_access = DocumentAccess.find_or_initialize_by(friendlier_id: row[0], institution_code: row[1]) document_access.update!(row.to_hash) end true end |
Instance Method Details
#reindex_document ⇒ Object
36 37 38 |
# File 'app/models/document_access.rb', line 36 def reindex_document document.save end |
#to_csv ⇒ Object
32 33 34 |
# File 'app/models/document_access.rb', line 32 def to_csv attributes.values end |