Sha256: 2c16181b40856972c9e4632e97341a040c876b8f5e27b500ba908adbb69c38e3

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

class Object

  # Issue a warning and maybe open a Pry session attached to the error or
  # binding passed.
  #
  # @example with error context
  #   begin
  #     (...)
  #   rescue => error
  #     warn("oops", pry: error)
  #   end
  # @example with binding context
  #   warn("oops", pry: binding)
  #
  # @param message [String] warning message
  # @param pry [Exception, Binding, nil] attach the Pry session to this error
  #   or binding
  def warn(message, pry: nil)
    $WARN_COUNTER = $WARN_COUNTER.to_i + 1
    Kernel.warn "WARNING #{$WARN_COUNTER}: #{message}".red
    if $PRY_ON_WARN == true || $PRY_ON_WARN == $WARN_COUNTER
      case pry
        when Exception then Pry::rescued(pry)
        when Binding then pry.pry
      end
    end
  end

  # Issue an informational message.
  #
  # @param message [String] informational message
  def info(message, color: :black)
    puts message.send(color)
  end

  # Issue a verbose informational message.
  #
  # @param message [String] verbose informational message
  def verbose_info(message, color: :blue)
    info(message, color: color) if $VERBOSE_INFO
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aipp-0.2.6 lib/core_ext/object.rb
aipp-0.2.5 lib/core_ext/object.rb