Module: GemHadar::Warn

Includes:
Term::ANSIColor
Included in:
GemHadar, SimpleCov, SimpleCov::ContextFormatter
Defined in:
lib/gem_hadar/warn.rb

Overview

A module that provides warning functionality with colored output.

This module enhances the standard warn method to display warning messages in orange color, making them more visible in terminal outputs. It is designed to be included in classes that need consistent warning message formatting throughout the application.

Examples:

Using the warn method from this module

class MyClass
  include GemHadar::SimpleCov::Warn

  def my_method
    warn "This is a warning message"
  end
end

Instance Method Summary collapse

Instance Method Details

#fail(*msgs) ⇒ void

This method returns an undefined value.

The fail method formats and displays failure messages using red colored output.

This method takes an array of message objects, applies red color formatting to string representations of the messages, and then passes them to the superclass’s fail method for display. The uplevel: 1 option ensures that the failure message originates from the caller’s context rather than from within this method itself.

Parameters:

  • msgs (Array<Object>)

    the array of message objects to display as failures



48
49
50
51
52
53
# File 'lib/gem_hadar/warn.rb', line 48

def fail(*msgs)
  msgs.map! do |a|
    a.respond_to?(:to_str) ? color(196) { a.to_str } : a
  end
  super(*msgs)
end

#warn(*msgs) ⇒ Object

The warn method displays warning messages using orange colored output.

This method takes an array of message strings, applies orange color formatting to each message, and then passes them to the superclass’s warn method for display. The uplevel: 1 option ensures that the warning originates from the caller’s context rather than from within this method itself.

Parameters:

  • msgs (Array<String>)

    the array of message strings to display as warnings



30
31
32
33
34
35
# File 'lib/gem_hadar/warn.rb', line 30

def warn(*msgs)
  msgs.map! do |a|
    a.respond_to?(:to_str) ? color(208) { a.to_str } : a
  end
  super(*msgs, uplevel: 1)
end