Skip to content

Commit

Permalink
Added support for setting custom defaults in ~/.aprc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dvorkin committed Apr 8, 2010
1 parent 7fe3842 commit 936d73e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
0.1.3
- Added support for setting custom defaults in ~/.aprc

0.1.2
- Correctly handle empty arrays and hashes
- Use alias_method instead of alias (fixes non-tty method aliasing)
- Added awesome_inspect method

0.1.1
- Added support for tableless ActiveRecord models
- Left align hash keys if @options[:indent] is negative

0.1.0
- Initial Release.

16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,19 @@ Supported color names:
}
rails>

### Known Issues ###

* Windows...
### Setting Custom Defaults ###
You can set your own default options by creating ``.aprc`` file in your home
directory. Within that file assign your defaults to ``AwesomePrint.defaults``.
For example:

# ~/.aprc file.
AwesomePrint.defaults = {
:indent => -2,
:color => {
:hash => :pale,
:class => :white
}
}

### Note on Patches/Pull Requests ###
* Fork the project on Github.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3
7 changes: 4 additions & 3 deletions awesome_print.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@

Gem::Specification.new do |s|
s.name = %q{awesome_print}
s.version = "0.1.2"
s.version = "0.1.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Michael Dvorkin"]
s.date = %q{2010-04-05}
s.date = %q{2010-04-07}
s.description = %q{Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports Rails ActiveRecord objects via included mixin.}
s.email = %q{mike@dvorkin.net}
s.extra_rdoc_files = [
"LICENSE",
"README.md"
]
s.files = [
"LICENSE",
"CHANGELOG",
"LICENSE",
"README.md",
"Rakefile",
"VERSION",
Expand Down
32 changes: 32 additions & 0 deletions lib/ap/awesome_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def initialize(options = {})
}.merge(options.delete(:color) || {})
}.merge(options)

load_custom_defaults

@indentation = @options[:indent].abs
Thread.current[AP] ||= []
end
Expand Down Expand Up @@ -196,4 +198,34 @@ def outdent
@outdent = ' ' * (@indentation - @options[:indent].abs)
end

# Load ~/.aprc file that can store custom defaults, for example:
#
# AwesomePrint.defaults = {
# :indent => -2,
# :color => {
# :trueclass => :red
# }
# }
#------------------------------------------------------------------------------
def load_custom_defaults
dotfile = File.join(ENV["HOME"], ".aprc")
if File.readable?(dotfile)
load dotfile
@options[:color].merge!(self.class.defaults.delete(:color) || {})
@options.merge!(self.class.defaults)
end
rescue => e
$stderr.puts "Could not load #{dotfile}: #{e}"
end

# Class accessors for custom defaults.
#------------------------------------------------------------------------------
def self.defaults
@@defaults ||= {}
end

def self.defaults=(*args)
@@defaults = *args
end

end

0 comments on commit 936d73e

Please sign in to comment.