Class: DailyReport
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DailyReport
- Includes:
- SharedBehaviors
- Defined in:
- app/models/daily_report.rb
Class Method Summary collapse
Instance Method Summary collapse
- #archive ⇒ Object
- #archive! ⇒ Object
- #delete_file! ⇒ Object
- #file_exists? ⇒ Boolean
- #generate! ⇒ Object
- #localdir ⇒ Object
- #localfile ⇒ Object
- #next_job ⇒ Object
- #parent ⇒ Object
- #queue_next! ⇒ Object
- #queue_now! ⇒ Object
- #save_as!(data, path) ⇒ Object
- #unarchive ⇒ Object
- #url(root) ⇒ Object
Methods included from SharedBehaviors
Class Method Details
.formatters ⇒ Object
24 25 26 |
# File 'app/models/daily_report.rb', line 24 def self.formatters Ruport::Controller::Table.formats.keys end |
Instance Method Details
#archive ⇒ Object
91 92 93 94 |
# File 'app/models/daily_report.rb', line 91 def archive self.archived = true save ? self : nil end |
#archive! ⇒ Object
96 97 98 99 |
# File 'app/models/daily_report.rb', line 96 def archive! self.archived = true save! end |
#delete_file! ⇒ Object
49 50 51 52 |
# File 'app/models/daily_report.rb', line 49 def delete_file! File.delete(localfile) if File.file?(localfile) true end |
#file_exists? ⇒ Boolean
45 46 47 |
# File 'app/models/daily_report.rb', line 45 def file_exists? File.file?(localfile) end |
#generate! ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/models/daily_report.rb', line 54 def generate! Dir.mkdir(localdir) unless File.directory?(localdir) touch(:generate_started_at) data = table.result data = apply_transform(data) val = save_as!(data, localfile) touch(:generate_ended_at) val end |
#localdir ⇒ Object
32 33 34 |
# File 'app/models/daily_report.rb', line 32 def localdir "#{Rails.root}/#{parent}" end |
#localfile ⇒ Object
36 37 38 |
# File 'app/models/daily_report.rb', line 36 def localfile "#{localdir}/#{filename}" end |
#next_job ⇒ Object
87 88 89 |
# File 'app/models/daily_report.rb', line 87 def next_job jobs.by_priority.first end |
#parent ⇒ Object
28 29 30 |
# File 'app/models/daily_report.rb', line 28 def parent "files/#{table.guid}" end |
#queue_next! ⇒ Object
72 73 74 75 76 77 78 |
# File 'app/models/daily_report.rb', line 72 def queue_next! job = GenerateReportJob.new(id, true) Delayed::Job.enqueue :payload_object => job, :priority => 10, :run_at => calculate_next_gen_time, :report_id => id end |
#queue_now! ⇒ Object
80 81 82 83 84 85 |
# File 'app/models/daily_report.rb', line 80 def queue_now! job = GenerateReportJob.new(id, false) Delayed::Job.enqueue :payload_object => job, :priority => 0, :report_id => id end |
#save_as!(data, path) ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/models/daily_report.rb', line 64 def save_as!(data, path) tempfile = "#{Rails.root}/process/#{Time.now.to_i}_#{rand(9999999)}_#{rand(9999999)}.tmp" return false unless data.as(formatter.to_sym, (formatter_data || {}).merge(:file => tempfile)) return false unless File.file?(tempfile) File.rename(tempfile, path) File.file?(path) end |
#unarchive ⇒ Object
101 102 103 104 |
# File 'app/models/daily_report.rb', line 101 def unarchive self.archived = false save ? self : nil end |