Class: Licensed::UI::Shell
- Inherits:
-
Object
- Object
- Licensed::UI::Shell
- Defined in:
- lib/licensed/ui/shell.rb
Constant Summary collapse
- LEVELS =
%w(silent error warn confirm info debug)
Instance Method Summary collapse
- #confirm(msg, newline = true) ⇒ Object
- #debug(msg, newline = true) ⇒ Object
- #error(msg, newline = true) ⇒ Object
- #info(msg, newline = true) ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #level=(level) ⇒ Object
- #level?(name = nil) ⇒ Boolean
- #silence ⇒ Object
- #warn(msg, newline = true) ⇒ Object
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
8 9 10 11 |
# File 'lib/licensed/ui/shell.rb', line 8 def initialize @shell = STDOUT.tty? ? Thor::Base.shell.new : Thor::Shell::Basic.new @level = ENV['DEBUG'] ? "debug" : "info" end |
Instance Method Details
#confirm(msg, newline = true) ⇒ Object
21 22 23 |
# File 'lib/licensed/ui/shell.rb', line 21 def confirm(msg, newline = true) @shell.say msg, :green, newline if level?("confirm") end |
#debug(msg, newline = true) ⇒ Object
13 14 15 |
# File 'lib/licensed/ui/shell.rb', line 13 def debug(msg, newline = true) @shell.say msg, nil, newline if level?("debug") end |
#error(msg, newline = true) ⇒ Object
29 30 31 |
# File 'lib/licensed/ui/shell.rb', line 29 def error(msg, newline = true) @shell.say msg, :red, newline if level?("error") end |
#info(msg, newline = true) ⇒ Object
17 18 19 |
# File 'lib/licensed/ui/shell.rb', line 17 def info(msg, newline = true) @shell.say msg, nil, newline if level?("info") end |
#level=(level) ⇒ Object
33 34 35 36 |
# File 'lib/licensed/ui/shell.rb', line 33 def level=(level) raise ArgumentError unless LEVELS.include?(level.to_s) @level = level end |
#level?(name = nil) ⇒ Boolean
38 39 40 |
# File 'lib/licensed/ui/shell.rb', line 38 def level?(name = nil) name ? LEVELS.index(name) <= LEVELS.index(@level) : @level end |
#silence ⇒ Object
42 43 44 45 46 47 |
# File 'lib/licensed/ui/shell.rb', line 42 def silence old_level, @level = @level, "silent" yield ensure @level = old_level end |
#warn(msg, newline = true) ⇒ Object
25 26 27 |
# File 'lib/licensed/ui/shell.rb', line 25 def warn(msg, newline = true) @shell.say msg, :yellow, newline if level?("warn") end |