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

Merge AwesomePrint.defaults when defined in ~/.irbrc

This commit is contained in:
Mike Dvorkin 2012-09-03 14:05:14 -07:00
parent fa958455ca
commit a939430d16
2 changed files with 18 additions and 4 deletions

View file

@ -129,10 +129,8 @@ module AwesomePrint
#------------------------------------------------------------------------------
def merge_custom_defaults!
dotfile = File.join(ENV["HOME"], ".aprc")
if File.readable?(dotfile)
load dotfile
merge_options!(AwesomePrint.defaults)
end
load dotfile if File.readable?(dotfile)
merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash)
rescue => e
$stderr.puts "Could not load #{dotfile}: #{e}"
end

View file

@ -86,4 +86,20 @@ EOS
markup.ai(:html => true).should == '<pre><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>'
end
end
describe "AwesomePrint.defaults" do
# See https://github.com/michaeldv/awesome_print/issues/98
it "should properly merge the defaults" do
AwesomePrint.defaults = { :indent => -2, :sort_keys => true }
hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
out = hash.ai(:plain => true)
out.should == <<-EOS.strip
{
[ 0, 0, 255 ] => :yellow,
"magenta" => "rgb(255, 0, 255)",
:red => "rgb(255, 0, 0)"
}
EOS
end
end
end