Class: BundleUpdateInteractive::CLI::MultiSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_update_interactive/cli/multi_select.rb

Defined Under Namespace

Classes: List

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, table:) ⇒ MultiSelect

Returns a new instance of MultiSelect.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bundle_update_interactive/cli/multi_select.rb', line 33

def initialize(title:, table:)
  @title = title
  @table = table
  @tty_prompt = TTY::Prompt.new(
    interrupt: lambda {
      puts
      exit(130)
    }
  )
  add_keybindings

  @pastel = BundleUpdateInteractive.pastel
end

Class Method Details

.prompt_for_gems_to_update(outdated_gems) ⇒ Object



26
27
28
29
30
31
# File 'lib/bundle_update_interactive/cli/multi_select.rb', line 26

def self.prompt_for_gems_to_update(outdated_gems)
  table = Table.new(outdated_gems)
  title = "#{outdated_gems.length} gems can be updated."
  chosen = new(title: title, table: table).prompt
  outdated_gems.slice(*chosen)
end

Instance Method Details

#promptObject



47
48
49
50
# File 'lib/bundle_update_interactive/cli/multi_select.rb', line 47

def prompt
  choices = table.gem_names.to_h { |name| [table.render_gem(name), name] }
  tty_prompt.invoke_select(List, title, choices, help: help)
end