Permalink
Browse files

Added support for setting custom defaults in ~/.aprc

  • Loading branch information...
1 parent 7fe3842 commit 936d73e6e94a7bbcab4b3c9a4021ec3f789ca3bf @michaeldv michaeldv committed Apr 8, 2010
Showing with 65 additions and 7 deletions.
  1. +15 −0 CHANGELOG
  2. +13 −3 README.md
  3. +1 −1 VERSION
  4. +4 −3 awesome_print.gemspec
  5. +32 −0 lib/ap/awesome_print.rb
View
@@ -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
@@ -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.
View
@@ -1 +1 @@
-0.1.2
+0.1.3
View
@@ -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",
View
@@ -29,6 +29,8 @@ def initialize(options = {})
}.merge(options.delete(:color) || {})
}.merge(options)
+ load_custom_defaults
+
@indentation = @options[:indent].abs
Thread.current[AP] ||= []
end
@@ -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.