Class: Hyrax::SelectCollectionTypeListPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/hyrax/select_collection_type_list_presenter.rb

Overview

Presents the list of collection type options that a user may choose from when deciding to create a new work

Instance Method Summary collapse

Constructor Details

#initialize(current_user) ⇒ SelectCollectionTypeListPresenter

Returns a new instance of SelectCollectionTypeListPresenter.

Parameters:

  • current_user (User)


5
6
7
# File 'app/presenters/hyrax/select_collection_type_list_presenter.rb', line 5

def initialize(current_user)
  @current_user = current_user
end

Instance Method Details

#any?Boolean

Returns are there any authorized types?.

Returns:

  • (Boolean)

    are there any authorized types?



18
19
20
21
# File 'app/presenters/hyrax/select_collection_type_list_presenter.rb', line 18

def any?
  return true if authorized_collection_types.present?
  false
end

#authorized_collection_typesObject

Return an array of authorized collection types.



24
25
26
# File 'app/presenters/hyrax/select_collection_type_list_presenter.rb', line 24

def authorized_collection_types
  @authorized_collection_types ||= Hyrax::CollectionTypes::PermissionsService.can_create_collection_types(user: @current_user)
end

#each {|a| ... } ⇒ Object

Yield Parameters:



38
39
40
# File 'app/presenters/hyrax/select_collection_type_list_presenter.rb', line 38

def each
  authorized_collection_types.each { |type| yield row_presenter.new(type) }
end

#first_collection_type {|a| ... } ⇒ CollectionType

Return or yield the first type in the list. This is used when the list only has a single element.

Yield Parameters:

Returns:



32
33
34
35
# File 'app/presenters/hyrax/select_collection_type_list_presenter.rb', line 32

def first_collection_type
  yield(authorized_collection_types.first) if block_given?
  authorized_collection_types.first
end

#many?Boolean

Returns are there many different types to choose?.

Returns:

  • (Boolean)

    are there many different types to choose?



13
14
15
# File 'app/presenters/hyrax/select_collection_type_list_presenter.rb', line 13

def many?
  authorized_collection_types.size > 1
end