Class: Zanzibar::Shell
- Inherits:
-
Object
- Object
- Zanzibar::Shell
- Defined in:
- lib/zanzibar/ui.rb
Overview
Prints messages out to stdout
Instance Attribute Summary collapse
-
#shell ⇒ Object
writeonly
The stream to write log messages (usually stdout).
Instance Method Summary collapse
-
#be_quiet! ⇒ Object
Enable silent mode.
-
#confirm(message = nil) ⇒ Object
Ask the user for confirmation unless we have silenced output.
-
#debug(message = nil) ⇒ Object
Write a debug message if debug is enabled.
-
#debug! ⇒ Object
Enable debug mode.
-
#error(message = nil) ⇒ Object
Print an error.
-
#info(message = nil) ⇒ Object
Write an info message unless we have silenced output.
-
#initialize(shell) ⇒ Shell
constructor
Logging options and initializing stream.
-
#warn(message = nil) ⇒ Object
Print a warning.
Constructor Details
#initialize(shell) ⇒ Shell
Logging options and initializing stream
13 14 15 16 17 |
# File 'lib/zanzibar/ui.rb', line 13 def initialize(shell) @shell = shell @quiet = false @debug = ENV['DEBUG'] end |
Instance Attribute Details
#shell=(value) ⇒ Object (writeonly)
The stream to write log messages (usually stdout)
9 10 11 |
# File 'lib/zanzibar/ui.rb', line 9 def shell=(value) @shell = value end |
Instance Method Details
#be_quiet! ⇒ Object
Enable silent mode
51 52 53 |
# File 'lib/zanzibar/ui.rb', line 51 def be_quiet! @quiet = true end |
#confirm(message = nil) ⇒ Object
Ask the user for confirmation unless we have silenced output
33 34 35 |
# File 'lib/zanzibar/ui.rb', line 33 def confirm( = nil) @shell.say( || yield, :green) unless @quiet end |
#debug(message = nil) ⇒ Object
Write a debug message if debug is enabled
21 22 23 |
# File 'lib/zanzibar/ui.rb', line 21 def debug( = nil) @shell.say( || yield) if @debug && !@quiet end |
#debug! ⇒ Object
Enable debug mode
57 58 59 |
# File 'lib/zanzibar/ui.rb', line 57 def debug! @debug = true end |
#error(message = nil) ⇒ Object
Print an error
45 46 47 |
# File 'lib/zanzibar/ui.rb', line 45 def error( = nil) @shell.say( || yield, :red) end |
#info(message = nil) ⇒ Object
Write an info message unless we have silenced output
27 28 29 |
# File 'lib/zanzibar/ui.rb', line 27 def info( = nil) @shell.say( || yield) unless @quiet end |
#warn(message = nil) ⇒ Object
Print a warning
39 40 41 |
# File 'lib/zanzibar/ui.rb', line 39 def warn( = nil) @shell.say( || yield, :yellow) end |