Module: FerretsOnFire::DSL::LoggerDSL
- Included in:
- FerretsOnFire::DSL
- Defined in:
- lib/ferrets_on_fire/dsl/logger_dsl.rb
Constant Summary collapse
- COLORS =
{ info: nil, warn: :yellow, error: :red, success: :green, question: :magenta, action: :light_blue }.freeze
- FANCY_PREFIXES =
{ info: 'ℹ️️ ', warn: '⚠️ ', error: '‼️️ ', success: '✨ ', question: "\n❓ ", action: '⚙️ ' }.freeze
- DEFAULT_PREFIXES =
{ info: '[i]', warn: '[!]', error: '[X]', success: '[✔]', question: "\n[?]", action: '[$]' }.freeze
- SUFFIXES =
{ info: '', warn: '', error: '', success: '', question: ' > ', action: '' }.freeze
Instance Method Summary collapse
- #action(msg) ⇒ Object
- #banner(string, color: :white, background: :black) ⇒ Object
-
#choose(msg, options, default: nil) ⇒ Object
Generates a question with the specified msg.
- #crash(msg, output, command: nil, exit: true) ⇒ Object
-
#error(msg) ⇒ Object
Outputs a error message.
- #highlight(str) ⇒ Object
-
#info(msg) ⇒ Object
Outputs a info message.
- #linebreak ⇒ Object
-
#success(msg) ⇒ Object
Outputs a success message.
-
#warn(msg) ⇒ Object
Outputs a warning message.
- #yes_no(msg, default = true) ⇒ Object
Instance Method Details
#action(msg) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 138 public def action(msg) print log(msg, :action) if $stdout.tty? return_value = block_given? ? yield : nil puts "\r#{log(msg, :success)}" return_value end |
#banner(string, color: :white, background: :black) ⇒ Object
43 44 45 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 43 public def (string, color: :white, background: :black) puts string.colorize(color: color, background: background) end |
#choose(msg, options, default: nil) ⇒ Object
Generates a question with the specified msg. If output is true (default) it will be printed.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 79 public def choose(msg, , default: nil) linebreak HighLine.new.choose do || .prompt = log(msg + (default.nil? ? '' : " (Default: #{default})"), :question) .flow = :columns_across .default = default unless default.nil? .index_suffix = ') ' .each do |opt| .choice(opt) { return opt } end end end |
#crash(msg, output, command: nil, exit: true) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 117 public def crash(msg, output, command: nil, exit: true) puts error msg puts puts '=====================[ CRASH REPORT ]====================='.red unless command.nil? puts puts 'COMMAND: '.red puts command end puts puts 'ERROR:'.red puts output puts puts '=========================================================='.red puts exit 1 if exit end |
#error(msg) ⇒ Object
Outputs a error message
62 63 64 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 62 public def error(msg) puts log(msg, :error) end |
#highlight(str) ⇒ Object
112 113 114 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 112 public def highlight(str) str.light_blue end |
#info(msg) ⇒ Object
Outputs a info message
49 50 51 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 49 public def info(msg) puts log(msg, :info) end |
#linebreak ⇒ Object
108 109 110 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 108 public def linebreak puts end |
#success(msg) ⇒ Object
Outputs a success message
70 71 72 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 70 public def success(msg) puts log(msg, :success) end |
#warn(msg) ⇒ Object
Outputs a warning message
55 56 57 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 55 public def warn(msg) puts log(msg, :warn) end |
#yes_no(msg, default = true) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ferrets_on_fire/dsl/logger_dsl.rb', line 94 public def yes_no(msg, default = true) answer = nil until answer == '' || answer =~ /^(y|n)$/i y = default ? 'Y' : 'y' n = default ? 'n' : 'N' answer = HighLine.new.ask(log("#{msg} (#{y}/#{n})", :question)) answer = default ? 'y' : 'n' if answer == '' end answer.downcase == 'y' end |