Class: Geet::Utils::ManualListSelection

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/geet/utils/manual_list_selection.rb

Constant Summary collapse

NO_SELECTION_KEY =
"(none)"
PAGER_SIZE =
16

Instance Method Summary collapse

Instance Method Details

#select_entries(entry_type, entries, name_method: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/geet/utils/manual_list_selection.rb', line 52

def select_entries(entry_type, entries, name_method: nil)
  return [] if entries.empty?

  check_entries(entries, entry_type)

  entries_map = create_entries_map(entries, name_method)

  T.cast(show_prompt(:multi_select, entry_type, entries_map), T::Array[T.type_parameter(:T)])
end

#select_entry(entry_type, entries, name_method: nil) ⇒ Object

selected entry. nil is returned if the null entry (NO_SELECTION_KEY) is selected, or if there are no entries.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/geet/utils/manual_list_selection.rb', line 26

def select_entry(entry_type, entries, name_method: nil)
  return nil if entries.empty?

  check_entries(entries, entry_type)

  entries = create_entries_map(entries, name_method)
  entries = add_no_selection_entry(entries)

  chosen_entry = show_prompt(:select, entry_type, entries)

  no_selection?(chosen_entry) ? nil : chosen_entry
end