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

Split out dotfile loading

This is so that we can stub the loading of the dotfile completely
instead of just trying to stub via it's implimentation. This also
makes it easier to only stub the dotfile loading instead of stubbing
all file access which then causes problems with other things, such
as Pry, which actually need to read from the filesystem.
This commit is contained in:
Gerard Caulfield 2016-08-27 23:29:43 +10:00
parent fa6f4d3768
commit 8aef1bde91
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3

View file

@ -137,11 +137,18 @@ module AwesomePrint
@options.merge!(options)
end
# This method needs to be mocked during testing so that it always loads
# predictable values
#---------------------------------------------------------------------------
def load_dotfile
dotfile = File.join(ENV['HOME'], '.aprc')
load dotfile if File.readable?(dotfile)
end
# Load ~/.aprc file with custom defaults that override default options.
#---------------------------------------------------------------------------
def merge_custom_defaults!
dotfile = File.join(ENV['HOME'], '.aprc')
load dotfile if File.readable?(dotfile)
load_dotfile
merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash)
rescue => e
$stderr.puts "Could not load #{dotfile}: #{e}"