Sha256: 580ace7841de8392c3c40dd7e9acec7e8981875eb7f33c27d91fb1ff3fde30ee

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

require 'zip'

module Pageflow
  module Panorama
    class Package < ActiveRecord::Base
      include UploadableFile

      processing_state_machine do
        state 'unpacking'
        state 'unpacked'
        state 'unpacking_failed'

        event :process do
          transition any => 'unpacking'
        end

        event :retry_unpacking do
          transition 'unpacking_failed' => 'unpacking'
        end

        before_transition on: :retry_unpacking do |package|
          JobStatusAttributes.reset(package, stage: :unpacking)
        end

        job UnpackPackageJob do
          on_enter 'unpacking'
          result :ok, state: 'unpacked'
          result :error, state: 'unpacking_failed'
        end
      end

      has_attached_file(:thumbnail, Pageflow.config.paperclip_s3_default_options
                          .merge(default_url: ':pageflow_placeholder',
                                 default_style: :thumbnail,
                                 styles: Pageflow.config.thumbnail_styles))

      def thumbnail_url(*args)
        thumbnail.url(*args)
      end

      def index_document_path
        if attachment_on_s3.present? && index_document
          File.join(Panorama.config.packages_base_path, unpack_base_path, index_document)
        end
      end

      def unpack_base_path
        attachment_on_s3.present? ? File.dirname(attachment_on_s3.path(:unpacked)) : nil
      end

      # UploadableFile-overrides
      def retry!
        retry_unpacking!
      end

      def ready?
        unpacked?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pageflow-panorama-2.4.0 app/models/pageflow/panorama/package.rb
pageflow-panorama-2.3.0 app/models/pageflow/panorama/package.rb
pageflow-panorama-2.2.0 app/models/pageflow/panorama/package.rb