Class: DailyTable
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DailyTable
- Includes:
- SharedBehaviors
- Defined in:
- app/models/daily_table.rb
Instance Method Summary collapse
- #archive ⇒ Object
- #fetch ⇒ Object
- #has_reports? ⇒ Boolean
- #metric_name ⇒ Object
- #result ⇒ Object
- #test ⇒ Object
- #unarchive ⇒ Object
Methods included from SharedBehaviors
Instance Method Details
#archive ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/daily_table.rb', line 58 def archive transaction do self.archived = true reports.each do |report| report.archive! end save! end return self rescue ActiveRecord::RecordInvalid return nil end |
#fetch ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/daily_table.rb', line 23 def fetch time = Time.now.to_i out = fetch_data out = apply_transform(out) atts = {} atts[:fetch_time_in_seconds] = Time.now.to_i - time atts[:column_names] = out.column_names self.attributes = atts save unless new_record? out end |
#has_reports? ⇒ Boolean
76 77 78 |
# File 'app/models/daily_table.rb', line 76 def has_reports? reports.size > 0 end |
#metric_name ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/models/daily_table.rb', line 49 def metric_name return "" if metric.blank? begin return metric.constantize.display_name rescue Exception => e return "#{metric} (unknown)" end end |
#result ⇒ Object
19 20 21 |
# File 'app/models/daily_table.rb', line 19 def result fetch end |
#test ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/daily_table.rb', line 38 def test # ouputs html of the table begin fetch.to_html.html_safe rescue => e out = "#{e.}" out += "\n\nTrace shown in development environment:\n#{e.backtrace.join("\n")}" if Rails.env.development? out.gsub("\n", "<br/>").html_safe end end |
#unarchive ⇒ Object
71 72 73 74 |
# File 'app/models/daily_table.rb', line 71 def unarchive self.archived = false save ? self : nil end |