Sha256: 57d6acf0bbdabd9be87398e5bdca12a0af0a6b0be502bb208f8ebb15cf097e91

Contents?: true

Size: 1.1 KB

Versions: 1

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:)
    $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

1 entries across 1 versions & 1 rubygems

Version Path
aipp-0.2.4 lib/core_ext/object.rb