Class: Workarea::Reports::Export

Inherits:
Object
  • Object
show all
Extended by:
Dragonfly::Model
Includes:
ApplicationDocument
Defined in:
app/models/workarea/reports/export.rb

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Instance Method Details

#nameObject



28
29
30
# File 'app/models/workarea/reports/export.rb', line 28

def name
  report_type.titleize
end

#process!Object



32
33
34
35
36
# File 'app/models/workarea/reports/export.rb', line 32

def process!
  set(started_at: Time.current)
  CSV.open(temp_path, 'w') { |csv| yield(csv) }
  update_attributes!(file: temp_path, completed_at: Time.current)
end

#reportObject



38
39
40
41
# File 'app/models/workarea/reports/export.rb', line 38

def report
  klass = "Workarea::Reports::#{report_type.camelize}".constantize
  report = klass.new(report_params)
end

#temp_pathObject



43
44
45
46
47
# File 'app/models/workarea/reports/export.rb', line 43

def temp_path
  @temp_path ||= Pathname
    .new(Dir.tmpdir)
    .join("#{report_type}_#{Time.current.to_s(:export)}.csv")
end