Module: SiteMaps::Primitive::Output
- Included in:
- Runner::EventListener
- Defined in:
- lib/site_maps/primitive/output.rb
Class Method Summary collapse
- .colorize(text, *attributes) ⇒ Object
- .formatted_runtime(number) ⇒ Object
- .print_backtrace(error, limit: -1,, **options) ⇒ Object
- .print_error(message_or_error, backtrace: false, **options) ⇒ Object
- .print_message(message, level: :info, output: $stdout, newline: true, **fields) ⇒ Object
- .runtime_padding(number, extra = 2) ⇒ Object
Class Method Details
.colorize(text, *attributes) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/site_maps/primitive/output.rb', line 21 def colorize(text, *attributes) if defined? Rainbow attributes.reduce(Rainbow(text)) { |p, a| p.public_send(a) } else text end end |
.formatted_runtime(number) ⇒ Object
13 14 15 |
# File 'lib/site_maps/primitive/output.rb', line 13 def formatted_runtime(number) colorize(sprintf("%.3f ms", number), :lightgray) end |
.print_backtrace(error, limit: -1,, **options) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/site_maps/primitive/output.rb', line 41 def print_backtrace(error, limit: -1, **) return unless error.respond_to?(:backtrace) return if error.backtrace.nil? error.backtrace[0..limit].each { |frame| print_error(frame, **) } end |
.print_error(message_or_error, backtrace: false, **options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/site_maps/primitive/output.rb', line 29 def print_error(, backtrace: false, **) [:level] ||= :error = .to_s (, output: :stderr, **) if .is_a?(Exception) && backtrace limit = backtrace.is_a?(Integer) ? backtrace : -1 print_backtrace(, limit: limit, level: [:level]) end end |
.print_message(message, level: :info, output: $stdout, newline: true, **fields) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/site_maps/primitive/output.rb', line 48 def (, level: :info, output: $stdout, newline: true, **fields) output = case output when :stdout, "stdout" $stdout when :stderr, "stderr" $stderr when IO, StringIO output else raise ArgumentError, "Invalid output #{output.inspect}" end = format(, **fields) newline ? output.puts() : output.print() end |
.runtime_padding(number, extra = 2) ⇒ Object
17 18 19 |
# File 'lib/site_maps/primitive/output.rb', line 17 def runtime_padding(number, extra = 2) " " * (extra + sprintf("%.3f ms", number).size) end |