Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quick-debug

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quick-debug

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Quick - debug!

When debugging in Ruby, print statements are still often the best tool for the job. But how many times have you found yourself typing stuff like this over and over?

def main
  puts "========= in main"
  movie_dirs.each do |movie_dir|
    Find.find(movie_dir) do |fn|
      if fn.is_movie?
        parent_dir = File.dirname(fn)
        movie = nil
        if movie_dirs.include? parent_dir or parent_dir.has_another_movie(fn)
          puts "========= in if movie_dirs..."
          movie = get_movie fn
          puts "========= movie: #{movie.inspect}"
        else
          movie = get_movie(fn, true)
        end
    .......

What if you could just do this instead?

def main
  D.bg
  movie_dirs.each do |movie_dir|
    Find.find(movie_dir) do |fn|
      if fn.is_movie?
        parent_dir = File.dirname(fn)
        movie = nil
        if movie_dirs.include? parent_dir or parent_dir.has_another_movie(fn)
          movie = get_movie fn
          D.bg{'movie'}
        else
          movie = get_movie(fn, true)
        end
    .......

Now you can.

Installation

In your Gemfile, add:

gem 'quick-debug'

or run this, then require the gem as such:

$ gem install quick-debug
require 'quick-debug'

For especially legacy/hostile environments, or if you want to use this really quickly, you can directly require the quick-debug.rb file in your code - it has no dependencies. If you do this often, a symlink could come in really useful. For example:

$ sudo ln -s /Library/Ruby/Gems/1.8/gems/quick-debug-0.0.1/lib/quick-debug.rb /quick-debug.rb

Then, from within your code:

require '/quick-debug'
def main
  D.bg
  movie_dirs.each do |movie_dir|
  ....

Usage

D.bg{'@somevar'}

Prints [<caller filename, method, and line number>] @somevar ~> <contents of @somevar.inspect> to STDOUT. Any object can be passed in, but it must be surrounded by quotes or be made a symbol. If the block is omitted, only the caller method and line number will be printed.

D.lg{'@somevar'}

Same as above, but prints to /tmp/quick-debug.txt instead. A short timestamp is also printed at the start of each line. To change the output filepath, do

D.logpath = '</some/path/log.txt>'
D.str{'@somevar'}

The above methods just return the deubg output as a string, rather than printing them anywhere. This can be very useful if you need to use your own logging framework, for example: logger.debug D.str{'@somevar'}.

D.disable :bg

prevents all D.bg statements from printing anything. You can also pass in :lg or :all to disable D.lg statements or just everything respectively. You can use

D.enable

to re-enable them. It accepts the same options.

D.bg(:force){'@somevar'}
D.lg(:force){'@somevar'}

The debug methods accept a :force argument, which will cause those calls to run even though that output location been disabled.

Happy Debugging!!

FAQs

Package last updated on 24 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc