Class: Hyrax::TolerantSelectService

Inherits:
QaSelectService show all
Defined in:
app/services/hyrax/tolerant_select_service.rb

Overview

A more tolerant ‘QaSelectService`. This service treats terms with no `active:` property as active terms, instead of erroring with `eKeyError`.

Instance Attribute Summary

Attributes inherited from QaSelectService

#authority

Instance Method Summary collapse

Methods inherited from QaSelectService

#include_current_value, #initialize, #label, #select_active_options, #select_all_options

Constructor Details

This class inherits a constructor from Hyrax::QaSelectService

Instance Method Details

#active?(id) ⇒ Boolean

Returns indicates whether the term is active; false if the term is inactive or does not exist; defaults to true when no key is given.

Returns:

  • (Boolean)

    indicates whether the term is active; false if the term is inactive or does not exist; defaults to true when no key is given



11
12
13
# File 'app/services/hyrax/tolerant_select_service.rb', line 11

def active?(id)
  authority.find(id)&.fetch('active', true)
end

#active_elementsEnumerable<Hash>

Returns:

  • (Enumerable<Hash>)

Raises:

  • (KeyError)

    when no ‘term’ value is present for the id



19
20
21
# File 'app/services/hyrax/tolerant_select_service.rb', line 19

def active_elements
  authority.all.select { |e| e.fetch('active', true) }
end