Class: Debrew::Menu Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Module for displaying a debugging menu.
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
- #entries ⇒ Object private
- #prompt ⇒ Object private
Class Method Summary collapse
- .choose {|menu| ... } ⇒ Object private
Instance Method Summary collapse
- #choice(name, &action) ⇒ Object private
- #initialize ⇒ void constructor private
Constructor Details
#initialize ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
34 35 36 |
# File 'debrew.rb', line 34 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
31 32 33 |
# File 'debrew.rb', line 31 def entries @entries end |
#prompt ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
31 32 33 |
# File 'debrew.rb', line 31 def prompt @prompt end |
Class Method Details
.choose {|menu| ... } ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'debrew.rb', line 42 def self.choose = new yield choice = T.let(nil, T.nilable(Entry)) while choice.nil? .entries.each_with_index { |e, i| puts "#{i + 1}. #{e.name}" } print .prompt unless .prompt.nil? input = $stdin.gets || exit input.chomp! i = input.to_i if i.positive? choice = .entries[i - 1] else possible = .entries.select { |e| e.name.start_with?(input) } case possible.size when 0 then puts "No such option" when 1 then choice = possible.first else puts "Multiple options match: #{possible.map(&:name).join(" ")}" end end end choice[:action].call end |
Instance Method Details
#choice(name, &action) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
38 39 40 |
# File 'debrew.rb', line 38 def choice(name, &action) entries << Entry.new(name.to_s, action) end |