Module: Gem::UserInteraction
- Includes:
- DefaultUserInteraction
- Included in:
- Command, CommandManager, ConfigFile, DependencyInstaller, Doctor, Ext::Builder, Indexer, Installer, Package, RDoc, RDoc, RemoteFetcher, Request, Request, Security::Policy, Server, SpecFetcher, Uninstaller, Validator
- Defined in:
- lib/rubygems/user_interaction.rb
Overview
UserInteraction allows RubyGems to interact with the user through standard methods that can be replaced with more-specific UI methods for different displays.
Since UserInteraction dispatches to a concrete UI class you may need to reference other classes for specific behavior such as Gem::ConsoleUI or Gem::SilentUI.
Example:
class X
include Gem::UserInteraction
def get_answer
n = ask("What is the meaning of life?")
end
end
Instance Method Summary collapse
-
#alert(statement, question = nil) ⇒ Object
Displays an alert
statement
. -
#alert_error(statement, question = nil) ⇒ Object
Displays an error
statement
to the error output location. -
#alert_warning(statement, question = nil) ⇒ Object
Displays a warning
statement
to the warning output location. -
#ask(question) ⇒ Object
Asks a
question
and returns the answer. -
#ask_for_password(prompt) ⇒ Object
Asks for a password with a
prompt
. -
#ask_yes_no(question, default = nil) ⇒ Object
Asks a yes or no
question
. -
#choose_from_list(question, list) ⇒ Object
Asks the user to answer
question
with an answer from the givenlist
. -
#say(statement = '') ⇒ Object
Displays the given
statement
on the standard output (or equivalent). -
#terminate_interaction(exit_code = 0) ⇒ Object
Terminates the RubyGems process with the given
exit_code
. -
#verbose(msg = nil) ⇒ Object
Calls
say
withmsg
or the results of the block if really_verbose is true.
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Instance Method Details
#alert(statement, question = nil) ⇒ Object
Displays an alert statement
. Asks a question
if given.
102 103 104 |
# File 'lib/rubygems/user_interaction.rb', line 102 def alert statement, question = nil ui.alert statement, question end |
#alert_error(statement, question = nil) ⇒ Object
Displays an error statement
to the error output location. Asks a question
if given.
110 111 112 |
# File 'lib/rubygems/user_interaction.rb', line 110 def alert_error statement, question = nil ui.alert_error statement, question end |
#alert_warning(statement, question = nil) ⇒ Object
Displays a warning statement
to the warning output location. Asks a question
if given.
118 119 120 |
# File 'lib/rubygems/user_interaction.rb', line 118 def alert_warning statement, question = nil ui.alert_warning statement, question end |
#ask(question) ⇒ Object
Asks a question
and returns the answer.
125 126 127 |
# File 'lib/rubygems/user_interaction.rb', line 125 def ask question ui.ask question end |
#ask_for_password(prompt) ⇒ Object
Asks for a password with a prompt
132 133 134 |
# File 'lib/rubygems/user_interaction.rb', line 132 def ask_for_password prompt ui.ask_for_password prompt end |
#ask_yes_no(question, default = nil) ⇒ Object
Asks a yes or no question
. Returns true for yes, false for no.
139 140 141 |
# File 'lib/rubygems/user_interaction.rb', line 139 def ask_yes_no question, default = nil ui.ask_yes_no question, default end |
#choose_from_list(question, list) ⇒ Object
Asks the user to answer question
with an answer from the given list
.
146 147 148 |
# File 'lib/rubygems/user_interaction.rb', line 146 def choose_from_list question, list ui.choose_from_list question, list end |
#say(statement = '') ⇒ Object
Displays the given statement
on the standard output (or equivalent).
153 154 155 |
# File 'lib/rubygems/user_interaction.rb', line 153 def say statement = '' ui.say statement end |
#terminate_interaction(exit_code = 0) ⇒ Object
Terminates the RubyGems process with the given exit_code
160 161 162 |
# File 'lib/rubygems/user_interaction.rb', line 160 def terminate_interaction exit_code = 0 ui.terminate_interaction exit_code end |
#verbose(msg = nil) ⇒ Object
Calls say
with msg
or the results of the block if really_verbose is true.
168 169 170 |
# File 'lib/rubygems/user_interaction.rb', line 168 def verbose msg = nil say(msg || yield) if Gem.configuration.really_verbose end |