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:
parent
894e35ebd9
commit
24b6192f57
4 changed files with 40 additions and 27 deletions
30
lib/ap.rb
30
lib/ap.rb
|
@ -3,16 +3,22 @@
|
|||
# Awesome Print is freely distributable under the terms of MIT license.
|
||||
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
||||
#------------------------------------------------------------------------------
|
||||
%w(array string method object class kernel).each do |file|
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/#{file}"
|
||||
#
|
||||
# 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
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/awesome_print"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(Logger)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
|
||||
|
||||
# Load the following under normal circumstatnces as well as in Rails
|
||||
# console when required from ~/.irbrc.
|
||||
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
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/awesome_print"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(Logger)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
|
||||
|
||||
# Load the following under normal circumstatnces as well as in Rails
|
||||
# console when required from ~/.irbrc.
|
||||
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)
|
||||
|
|
|
@ -7,19 +7,20 @@
|
|||
# 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'
|
||||
#
|
||||
%w(array string method object class kernel).each do |file|
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/#{file}"
|
||||
unless defined?(AwesomePrint)
|
||||
%w(array string method object class kernel).each do |file|
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/#{file}"
|
||||
end
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/awesome_print"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(Logger)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
|
||||
|
||||
# Load the following under normal circumstatnces as well as in Rails
|
||||
# console when required from ~/.irbrc.
|
||||
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
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/awesome_print"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(Logger)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(ActionView)
|
||||
|
||||
# Load the following under normal circumstatnces as well as in Rails
|
||||
# console when required from ~/.irbrc.
|
||||
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)
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue