Sha256: 11a586ed680239c7e9e33fd5a74482e84a082079c347f586388dc64c7dbf8026

Contents?: true

Size: 1002 Bytes

Versions: 54

Compression:

Stored size: 1002 Bytes

Contents

module Hyrax
  class SingleUseLinkPresenter
    include ActionView::Helpers::TranslationHelper

    attr_reader :link

    delegate :downloadKey, :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.downloadKey.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

54 entries across 54 versions & 2 rubygems

Version Path
hyrax-2.9.6 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.9.5 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.9.4 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.9.3 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.9.2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.9.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.9.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.8.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.7.2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.7.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.7.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.6.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.5.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.5.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.4.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.4.0 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.3.3 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.3.2 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-2.3.1 app/presenters/hyrax/single_use_link_presenter.rb
hyrax-1.1.1 app/presenters/hyrax/single_use_link_presenter.rb