Class: Hyrax::ContextualPath

Inherits:
Object
  • Object
show all
Includes:
ActionDispatch::Routing::PolymorphicRoutes
Defined in:
app/services/hyrax/contextual_path.rb

Overview

Provides a polymorphic path for a target object (presenter) nested under the path of the parent, if given.

Examples:

Hyrax::ContextualPath.new(my_file_set, parent_object).show
# => "/concerns/parent/id4parent/file_sets/id4file_set"

with a nil parent

Hyrax::ContextualPath.new(my_file_set, nil).show
# => "/concerns/file_sets/id4file_set"

See Also:

  • WorkShowPresenter#contextual_path

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presenter, parent_presenter) ⇒ ContextualPath

Returns a new instance of ContextualPath.

Parameters:

  • presenter (#model_name)

    an ActiveModel-like target object

  • parent_presenter (#id, nil)

    an ActiveModel-like presenter for the target’s parent



28
29
30
31
# File 'app/services/hyrax/contextual_path.rb', line 28

def initialize(presenter, parent_presenter)
  @presenter = presenter
  @parent_presenter = parent_presenter
end

Instance Attribute Details

#parent_presenterObject (readonly)



22
23
24
# File 'app/services/hyrax/contextual_path.rb', line 22

def parent_presenter
  @parent_presenter
end

#presenterObject (readonly)



22
23
24
# File 'app/services/hyrax/contextual_path.rb', line 22

def presenter
  @presenter
end

Instance Method Details

#showString

Returns:

  • (String)


35
36
37
38
39
40
41
42
43
# File 'app/services/hyrax/contextual_path.rb', line 35

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