Sha256: 7b67f3c2dfbe5d317f14d6d43f7751824d0730cd3570a4a46aaf6c5f47e8d1aa

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

# frozen_string_literal: true

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

    def attachment_url(attachment)
      return nil unless attachment.attached?

      rails_blob_url(attachment, host: attachment_host)
    end

    private

    def attachment_host
      ENV.fetch('ATTACHMENTS_HOST', heroku_attachment_host)
    end

    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

1 entries across 1 versions & 1 rubygems

Version Path
mobile_workflow-0.11.0 app/models/concerns/mobile_workflow/attachable.rb