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)

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

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?


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

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

#authorized_collection_typesObject

Return an array of authorized collection types.


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

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

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

Yield Parameters:


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

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:


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

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?


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

def many?
  authorized_collection_types.size > 1
end