Sha256: 344c4388044959a8b447d698f0056607be1265da8316d4150dd9cf6dabe57399

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
module Hyrax
  ##
  # @api public
  #
  # Provides a polymorphic path for a target object (presenter) nested under the
  # path of the parent, if given.
  #
  # @see WorkShowPresenter#contextual_path
  #
  # @example
  #   Hyrax::ContextualPath.new(my_file_set, parent_object).show
  #   # => "/concerns/parent/id4parent/file_sets/id4file_set"
  #
  # @example with a nil parent
  #   Hyrax::ContextualPath.new(my_file_set, nil).show
  #   # => "/concerns/file_sets/id4file_set"
  #
  class ContextualPath
    include Rails.application.routes.url_helpers
    include ActionDispatch::Routing::PolymorphicRoutes
    attr_reader :presenter, :parent_presenter

    ##
    # @param presenter [#model_name] an ActiveModel-like target object
    # @param parent_presenter [#id, nil] an ActiveModel-like presenter for the
    #   target's parent
    def initialize(presenter, parent_presenter)
      @presenter = presenter
      @parent_presenter = parent_presenter
    end

    ##
    # @return [String]
    def show
      if parent_presenter
        polymorphic_path([:hyrax, :parent, presenter.model_name.singular.to_sym],
                         parent_id: parent_presenter.id,
                         id: presenter.id)
      else
        polymorphic_path([presenter])
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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