Class: Report

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AASM
Defined in:
app/models/report.rb

Instance Method Summary collapse

Instance Method Details

#csv_column_namesObject



65
66
67
68
# File 'app/models/report.rb', line 65

def csv_column_names
  raise MintReporter::Undefined,
    "Subclasses of Report must implement csv_column_names"
end

#csv_row(record) ⇒ Object



70
71
72
73
# File 'app/models/report.rb', line 70

def csv_row(record)
  raise MintReporter::Undefined,
    "Subclasses of Report must implement csv_row"
end

#generate_csvObject



40
41
42
# File 'app/models/report.rb', line 40

def generate_csv
  CSVGenerationWorker.perform_async(id)
end

#generate_csv!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/report.rb', line 44

def generate_csv!
  generating_csv!
  file = Tempfile.new(["report-#{id}", '.csv'])
  begin
    CSV.open(file, "wb") do |csv|
      csv << csv_column_names

      scoped_records.each do |record|
        csv << csv_row(record)
      end
    end
    self.csv = file
    save
    file.close
    csv_generated!
  rescue Exception => e
    csv_failure!
    raise e
  end
end

#recordsObject



75
76
77
78
# File 'app/models/report.rb', line 75

def records
  raise MintReporter::Undefined,
    "Subclasses of Report must implement records"
end