Sha256: e445c36abd258ad99e09a399ec2b75817666d7f814ebebb054eb592beb4894a8

Contents?: true

Size: 1.76 KB

Versions: 9

Compression:

Stored size: 1.76 KB

Contents

module Pageflow
  module Chart
    class ScrapedSite < ActiveRecord::Base
      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')

      do_not_validate_attachment_file_type(:javascript_file)
      do_not_validate_attachment_file_type(:stylesheet_file)
      do_not_validate_attachment_file_type(:html_file)
      do_not_validate_attachment_file_type(:csv_file)

      state_machine initial: 'unprocessed' do
        extend StateMachineJob::Macro

        state 'unprocessed'
        state 'processing'
        state 'processing_failed'
        state 'processed'

        event :process do
          transition 'unprocessed' => 'processing'
        end

        event :reprocess do
          transition 'processed' => 'processing'
          transition 'processing_failed' => 'processing'
        end

        job ScrapeSiteJob do
          on_enter 'processing'
          result ok: 'processed'
          result error: 'processing_failed'
        end
      end

      before_create do
        self.use_custom_theme = Chart.config.use_custom_theme
        true
      end

      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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pageflow-chart-2.1.0 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-2.0.0 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-1.2.0 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-1.1.0 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-1.0.1 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-1.0.0 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-0.2.2 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-0.2.1 app/models/pageflow/chart/scraped_site.rb
pageflow-chart-0.2.0 app/models/pageflow/chart/scraped_site.rb