1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Added support for setting custom defaults in ~/.aprc

This commit is contained in:
Mike Dvorkin 2010-04-07 21:31:21 -07:00
parent 7fe38425a5
commit 936d73e6e9
5 changed files with 64 additions and 6 deletions

15
CHANGELOG Normal file
View file

@ -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.

View file

@ -144,9 +144,19 @@ Supported color names:
}
rails>
### Known Issues ###
### 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:
* Windows...
# ~/.aprc file.
AwesomePrint.defaults = {
:indent => -2,
:color => {
:hash => :pale,
:class => :white
}
}
### Note on Patches/Pull Requests ###
* Fork the project on Github.

View file

@ -1 +1 @@
0.1.2
0.1.3

View file

@ -5,11 +5,11 @@
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 = [
@ -17,7 +17,8 @@ Gem::Specification.new do |s|
"README.md"
]
s.files = [
"LICENSE",
"CHANGELOG",
"LICENSE",
"README.md",
"Rakefile",
"VERSION",

View file

@ -29,6 +29,8 @@ class AwesomePrint
}.merge(options.delete(:color) || {})
}.merge(options)
load_custom_defaults
@indentation = @options[:indent].abs
Thread.current[AP] ||= []
end
@ -196,4 +198,34 @@ class AwesomePrint
@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