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

Load necessary files when Rails console is running under Pry

This commit is contained in:
Mike Dvorkin 2012-09-05 19:41:54 -07:00
parent 5f00926d80
commit 67cde1be8d
2 changed files with 17 additions and 7 deletions

View file

@ -4,8 +4,8 @@
# 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.
# AwesomePrint might be loaded implicitly through ~/.irbrc or ~/.pryrc
# so do nothing for subsequent requires.
#
unless defined?(AwesomePrint::Inspector)
%w(array string method object class kernel).each do |file|
@ -16,13 +16,15 @@ unless defined?(AwesomePrint::Inspector)
require File.dirname(__FILE__) + "/awesome_print/formatter"
require File.dirname(__FILE__) + "/awesome_print/version"
require File.dirname(__FILE__) + "/awesome_print/core_ext/logger" if defined?(Logger)
#
# Load the following under normal circumstances as well as in Rails
# console when required from ~/.irbrc.
require File.dirname(__FILE__) + "/awesome_print/ext/active_record" if defined?(ActiveRecord) || (defined?(IRB) && ENV['RAILS_ENV'])
require File.dirname(__FILE__) + "/awesome_print/ext/active_support" if defined?(ActiveSupport) || (defined?(IRB) && ENV['RAILS_ENV'])
# console when required from ~/.irbrc or ~/.pryrc.
#
require File.dirname(__FILE__) + "/awesome_print/ext/active_record" if defined?(ActiveRecord) || AwesomePrint.rails_console?
require File.dirname(__FILE__) + "/awesome_print/ext/active_support" if defined?(ActiveSupport) || AwesomePrint.rails_console?
#
# Load remaining extensions.
#
require File.dirname(__FILE__) + "/awesome_print/ext/action_view" if defined?(ActionView::Base)
require File.dirname(__FILE__) + "/awesome_print/ext/mongo_mapper" if defined?(MongoMapper)
require File.dirname(__FILE__) + "/awesome_print/ext/mongoid" if defined?(Mongoid)

View file

@ -14,6 +14,14 @@ module AwesomePrint
def force_colors!(value = true)
@force_colors = value
end
def console?
defined?(IRB) || defined?(Pry)
end
def rails_console?
console? && (defined?(Rails::Console) || ENV["RAILS_ENV"])
end
end
class Inspector