0.0
No commit activity in last 3 years
No release in over 3 years
Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports Rails ActiveRecord objects via included mixin.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.2.9
 Project Readme

Awesome Dump

Awesome Dump is Ruby library that dumps Ruby objects as nested hashes/arrays, exposing their internal structure in a form safe for conversion to JSON, YAML, or other data formats.

Notes:

Installation

# Installing as Rails plugin
$ ruby script/plugin install git://github.com/slippyd/awesome_dump.git

# Installing as a Ruby library
$ git clone git://github.com/slippyd/awesome_dump.git lib/awesome_dump

# Installing as a Ruby library, with Git submodules
$ git submodule add git://github.com/slippyd/awesome_dump.git lib/awesome_dump
$ git submodule init
$ git submodule update

# Cloning the repository
$ git clone git://github.com/slippyd/awesome_dump.git

Usage

require 'ad'
some_object.ad

require 'ad', 'json'
some_object.ad(:escape => :safe).to_json

require 'ad', 'yaml'
some_object.ad(:escape => :quote).to_yaml

Supported options:

  • ":escape => :safe": Quotes constructs that probably won't translate well into languages other than Ruby (e.g. symbols, classes). Can result in ambigious or lossy results if naming conflicts occur.
  • ":escape => :quote": Quotes every piece of data that's dumped (i.e. numbers become strings and Strings become strings that start and end with a quote). Theoretically, this conversion should be reversible back into the original data.

Examples

Ruby:

require 'rubygems'
require 'json'
require 'awesome_dump/init'

class Cow
  def initialize
    @moo = true
  end
end

data = [false, 42, %w(forty two), {:how => 'now', 'brown' => Cow.new}]
puts "inspect:\n\t" + data.inspect
puts "ad.inspect:\n\t" + data.ad.inspect
puts "to_json:\n\t" + data.to_json
puts "ad(:escape => :safe).to_json:\n\t" + data.ad(:escape => :safe).to_json

Output:

inspect:
	[false, 42, ["forty", "two"], {:how=>"now", "brown"=>#<Cow:0x101069210 @moo=true>}]
ad.inspect:
	[false, 42, ["forty", "two"], {:how=>"now", "brown"=>{:@moo=>true, :class=>Cow, :object_id=>2156087560}}]
to_json:
	[false,42,["forty","two"],{"how":"now","brown":"#<Cow:0x101069210>"}]
ad(:escape => :safe).to_json:
	[false,42,["forty","two"],{":how":"now","brown":{"class":"Cow","@moo":true,"object_id":2156087560}}]

Setting Custom Defaults

You can set your own default options by creating .adrc file in your home directory. Within that file assign your defaults to AwesomeDump.defaults. For example:

# ~/.adrc file.
AwesomeDump.defaults = {
  :escape => :quote
}

Note on Patches/Pull Requests

  • Fork the project on Github.
  • Make your feature addition or bug fix.
  • Add specs for it, making sure $ rake spec is all green.
  • Commit, do not mess with rakefile, version, or history.
  • Send me a pull request.

Contributors

awesome_print:

License

Copyright (c) 2010 Slippy Douglas 'awesome_dump' + 64.chr + 'slippyd.com'

Based on awesome_print, Copyright (c) 2010 Michael Dvorkin %w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"

Released under the MIT license. See LICENSE file for details.