Class: Fontist::Utils::UI
- Inherits:
-
Thor
- Object
- Thor
- Fontist::Utils::UI
- Defined in:
- lib/fontist/utils/ui.rb
Constant Summary collapse
- ALL_LEVELS =
%i[debug info warn error fatal unknown].freeze
Class Method Summary collapse
- .ask(message, options = {}) ⇒ Object
- .debug(message) ⇒ Object
- .debug? ⇒ Boolean
- .default_level ⇒ Object
- .env_level ⇒ Object
- .error(message) ⇒ Object
- .level ⇒ Object
- .level=(level) ⇒ Object
- .log_levels ⇒ Object
- .print(message) ⇒ Object
- .say(message) ⇒ Object
- .success(message) ⇒ Object
Class Method Details
.ask(message, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/fontist/utils/ui.rb', line 46 def self.ask(, = {}) new.ask(, ) rescue Errno::EBADF say(<<~MSG.chomp) ERROR: Fontist is unable to obtain agreement without an interactive prompt. Please provide explicit agreement at execution or re-run Fontist with an interactive prompt. MSG "error" end |
.debug(message) ⇒ Object
60 61 62 |
# File 'lib/fontist/utils/ui.rb', line 60 def self.debug() new.say() if debug? end |
.debug? ⇒ Boolean
26 27 28 |
# File 'lib/fontist/utils/ui.rb', line 26 def self.debug? log_levels.include?(:debug) end |
.default_level ⇒ Object
30 31 32 |
# File 'lib/fontist/utils/ui.rb', line 30 def self.default_level :fatal end |
.env_level ⇒ Object
22 23 24 |
# File 'lib/fontist/utils/ui.rb', line 22 def self.env_level ENV["FONTIST_LOG"]&.to_sym end |
.error(message) ⇒ Object
38 39 40 |
# File 'lib/fontist/utils/ui.rb', line 38 def self.error() new.say(, :red) if log_levels.include?(:warn) end |
.level ⇒ Object
18 19 20 |
# File 'lib/fontist/utils/ui.rb', line 18 def self.level @level ||= env_level || default_level end |
.level=(level) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/fontist/utils/ui.rb', line 8 def self.level=(level) unless ALL_LEVELS.include?(level) raise Errors::GeneralError, "Unknown log level: #{level.inspect}. " \ "Supported levels are #{ALL_LEVELS.map(&:inspect).join(', ')}." end @level = level end |
.log_levels ⇒ Object
64 65 66 67 |
# File 'lib/fontist/utils/ui.rb', line 64 def self.log_levels @log_levels ||= {} @log_levels[@level] ||= ALL_LEVELS.drop_while { |l| l != level } end |
.print(message) ⇒ Object
56 57 58 |
# File 'lib/fontist/utils/ui.rb', line 56 def self.print() super if log_levels.include?(:info) end |
.say(message) ⇒ Object
42 43 44 |
# File 'lib/fontist/utils/ui.rb', line 42 def self.say() new.say() if log_levels.include?(:info) end |
.success(message) ⇒ Object
34 35 36 |
# File 'lib/fontist/utils/ui.rb', line 34 def self.success() new.say(, :green) if log_levels.include?(:info) end |