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

Avoid loading awesome_print more than once (ex. ~/.irbrc and then Rails console)

This commit is contained in:
Mike Dvorkin 2011-05-13 14:42:04 -07:00
parent 894e35ebd9
commit 24b6192f57
4 changed files with 40 additions and 27 deletions

View file

@ -3,6 +3,11 @@
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
#
# AwesomePrint might be loaded implicitly through ~/.irbrc so do nothing
# for subsequent requires.
#
unless defined?(AwesomePrint)
%w(array string method object class kernel).each do |file|
require File.dirname(__FILE__) + "/ap/core_ext/#{file}"
end
@ -16,3 +21,4 @@ require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(ActiveRecord) || (defined?(IRB) && ENV['RAILS_ENV'])
require File.dirname(__FILE__) + "/ap/mixin/active_support" if defined?(ActiveSupport) || (defined?(IRB) && ENV['RAILS_ENV'])
require File.dirname(__FILE__) + "/ap/mixin/mongo_mapper" if defined?(MongoMapper)
end

View file

@ -7,9 +7,9 @@
# This is the copy of original 'ap.rb' file that matches the gem name. It makes
# it possible to omit the :require part in bundler's Gemfile:
#
# gem 'awesome_print', '>= 0.2.1', :require => 'ap'
# gem 'awesome_print', '>= 3.0.0'
# gem 'awesome_print', '>= 0.4.0'
#
unless defined?(AwesomePrint)
%w(array string method object class kernel).each do |file|
require File.dirname(__FILE__) + "/ap/core_ext/#{file}"
end
@ -23,3 +23,4 @@ require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(ActiveRecord) || (defined?(IRB) && ENV['RAILS_ENV'])
require File.dirname(__FILE__) + "/ap/mixin/active_support" if defined?(ActiveSupport) || (defined?(IRB) && ENV['RAILS_ENV'])
require File.dirname(__FILE__) + "/ap/mixin/mongo_mapper" if defined?(MongoMapper)
end

View file

@ -467,6 +467,12 @@ EOS
self.stub!(:puts)
(ap object).should == object
end
# Require different file name this time (lib/ap.rb vs. lib/awesome_print).
it "several require 'awesome_print' should do no harm" do
require File.expand_path(File.dirname(__FILE__) + '/../lib/ap')
lambda { rand.ai }.should_not raise_error
end
end
describe "HTML output" do

View file

@ -10,7 +10,7 @@
#
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'ap'
require 'awesome_print'
def stub_dotfile!
dotfile = File.join(ENV["HOME"], ".aprc")