Sha256: 652afa99b8de7417c2228e001b2a6d7a478895a839f0100ddaa848a4f391b611

Contents?: true

Size: 1022 Bytes

Versions: 25

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  class SingleUseLinkPresenter
    include ActionView::Helpers::TranslationHelper

    attr_reader :link

    delegate :download_key, :expired?, :to_param, to: :link

    # @param link [SingleUseLink]
    def initialize(link)
      @link = link
    end

    def human_readable_expiration
      if hours < 1
        t('hyrax.single_use_links.expiration.lesser_time')
      else
        t('hyrax.single_use_links.expiration.time', value: hours)
      end
    end

    def short_key
      link.download_key.first(6)
    end

    def link_type
      if download?
        t('hyrax.single_use_links.download.type')
      else
        t('hyrax.single_use_links.show.type')
      end
    end

    def url_helper
      if download?
        "download_single_use_link_url"
      else
        "show_single_use_link_url"
      end
    end

    private

    def download?
      link.path =~ /downloads/
    end

    def hours
      (link.expires - Time.zone.now).to_i / 3600
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-5.0.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-5.0.0.rc3 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-5.0.0.rc2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-5.0.0.rc1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.6.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-4.0.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-4.0.0.rc3 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-4.0.0.rc2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-4.0.0.rc1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.5.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-4.0.0.beta2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.4.2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-4.0.0.beta1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.4.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.4.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.3.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.2.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.1.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-3.0.2 app/presenters/hyrax/single_use_link_presenter.rb