Sha256: 1e7c3771d1e6fba1cb30ea19dbd52b100bb9febff4bd37e1a5010cb7e30cc071

Contents?: true

Size: 936 Bytes

Versions: 6

Compression:

Stored size: 936 Bytes

Contents

module MobileWorkflow
  module Attachable
    extend ActiveSupport::Concern
    include Rails.application.routes.url_helpers

    def preview_url(attachment, options: { resize_to_fill: [200, 200] })
      return nil unless attachment.attached?

      if attachment.image?
        rails_representation_url(attachment.variant(options), host: heroku_attachment_host)
      elsif attachment.previewable?
        rails_representation_url(attachment.preview(options), host: heroku_attachment_host)
      else
        return nil
      end
    end

    def attachment_url(attachment)
      return nil unless attachment.attached?
    
      rails_blob_url(attachment, host: heroku_attachment_host)
    end

    private

    def heroku_attachment_host
      # TODO: MBS - move this to a configuration property
      app_name = Rails.env.test? ? 'test-app' : ENV.fetch('HEROKU_APP_NAME')
      "https://#{app_name}.herokuapp.com"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mobile_workflow-0.10.0 app/models/concerns/mobile_workflow/attachable.rb
mobile_workflow-0.9.0 app/models/concerns/mobile_workflow/attachable.rb
mobile_workflow-0.8.9 app/models/concerns/mobile_workflow/attachable.rb
mobile_workflow-0.7.9 app/models/concerns/mobile_workflow/attachable.rb
mobile_workflow-0.7.8 app/models/concerns/mobile_workflow/attachable.rb
mobile_workflow-0.7.7 app/models/concerns/mobile_workflow/attachable.rb