app/models/pageflow/chart/scraped_site.rb in pageflow-chart-2.1.0 vs app/models/pageflow/chart/scraped_site.rb in pageflow-chart-2.2.0
- old
+ new
@@ -1,8 +1,10 @@
module Pageflow
module Chart
class ScrapedSite < ActiveRecord::Base
+ include Pageflow::ReusableFile
+
has_attached_file :javascript_file, Chart.config.paperclip_options(extension: 'js')
has_attached_file :stylesheet_file, Chart.config.paperclip_options(extension: 'css')
has_attached_file :html_file, Chart.config.paperclip_options(extension: 'html')
has_attached_file :csv_file, Chart.config.paperclip_options(basename: 'data', extension: 'csv')
@@ -21,10 +23,14 @@
event :process do
transition 'unprocessed' => 'processing'
end
+ event :skip_reprocessing_imported_site do
+ transition 'unprocessed' => 'processed'
+ end
+
event :reprocess do
transition 'processed' => 'processing'
transition 'processing_failed' => 'processing'
end
@@ -42,20 +48,45 @@
def csv_url
URI.join(url, 'data.csv').to_s
end
- def as_json(*)
- super.merge(html_file_url: html_file_url)
- end
-
def html_file_url
return unless html_file.try(:path)
if Chart.config.scraped_sites_root_url.present?
File.join(Chart.config.scraped_sites_root_url, html_file.path)
else
html_file.url
end
+ end
+
+ # ReusableFile-overrides:
+ def url
+ read_attribute(:url)
+ end
+
+ def retryable?
+ processing_failed?
+ end
+
+ def ready?
+ processed?
+ end
+
+ def publish!
+ if html_file.present?
+ skip_reprocessing_imported_site!
+ else
+ process!
+ end
+ end
+
+ def retry!
+ reprocess!
+ end
+
+ def attachments_for_export
+ [javascript_file, stylesheet_file, html_file, csv_file]
end
end
end
end