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
- #newline ⇒ Object
- #silence ⇒ Object
- #warn(msg, newline = true) ⇒ Object
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
9 10 11 12 |
# File 'lib/licensed/ui/shell.rb', line 9 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
22 23 24 |
# File 'lib/licensed/ui/shell.rb', line 22 def confirm(msg, newline = true) @shell.say msg, :green, newline if level?("confirm") end |
#debug(msg, newline = true) ⇒ Object
14 15 16 |
# File 'lib/licensed/ui/shell.rb', line 14 def debug(msg, newline = true) @shell.say msg, nil, newline if level?("debug") end |
#error(msg, newline = true) ⇒ Object
30 31 32 |
# File 'lib/licensed/ui/shell.rb', line 30 def error(msg, newline = true) @shell.say msg, :red, newline if level?("error") end |
#info(msg, newline = true) ⇒ Object
18 19 20 |
# File 'lib/licensed/ui/shell.rb', line 18 def info(msg, newline = true) @shell.say msg, nil, newline if level?("info") end |
#level=(level) ⇒ Object
38 39 40 41 |
# File 'lib/licensed/ui/shell.rb', line 38 def level=(level) raise ArgumentError unless LEVELS.include?(level.to_s) @level = level end |
#level?(name = nil) ⇒ Boolean
43 44 45 |
# File 'lib/licensed/ui/shell.rb', line 43 def level?(name = nil) name ? LEVELS.index(name) <= LEVELS.index(@level) : @level end |
#newline ⇒ Object
34 35 36 |
# File 'lib/licensed/ui/shell.rb', line 34 def newline info "" end |
#silence ⇒ Object
47 48 49 50 51 52 |
# File 'lib/licensed/ui/shell.rb', line 47 def silence old_level, @level = @level, "silent" yield ensure @level = old_level end |
#warn(msg, newline = true) ⇒ Object
26 27 28 |
# File 'lib/licensed/ui/shell.rb', line 26 def warn(msg, newline = true) @shell.say msg, :yellow, newline if level?("warn") end |