diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-22 18:06:08 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-22 18:06:08 +0100 |
commit | f42c77f927eb49b00e84d355e07de48723d03fcb (patch) | |
tree | 2a459814a9708f292c99e9c5e99dd41d2d801353 /railties/lib | |
parent | a026b4c983681b71d876ea37958c3e5bc605acac (diff) | |
download | rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.gz rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.bz2 rails-f42c77f927eb49b00e84d355e07de48723d03fcb.zip |
Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH]
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/initializer.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/backtrace_cleaner.rb | 34 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 7 |
3 files changed, 46 insertions, 3 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 16abe62d1b..fcf6ea3feb 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -39,6 +39,14 @@ module Rails nil end end + + def backtrace_cleaner + @@backtrace_cleaner ||= begin + # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded + require 'rails/backtrace_cleaner' + Rails::BacktraceCleaner.new + end + end def root if defined?(RAILS_ROOT) diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb new file mode 100644 index 0000000000..ffc5ef42aa --- /dev/null +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -0,0 +1,34 @@ +module Rails + class BacktraceCleaner < ActiveSupport::BacktraceCleaner + ERB_METHOD_SIG = /:in `_run_erb_.*/ + + VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) + MONGREL_DIRS = %w( lib/mongrel bin/mongrel ) + RAILS_NOISE = %w( script/server ) + RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) + + ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE + + + def initialize + super + add_filter { |line| line.sub(RAILS_ROOT, '') } + add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + end + end + + + # For installing the BacktraceCleaner in the test/unit + module BacktraceFilterForTestUnit #:nodoc: + def self.included(klass) + klass.send :alias_method_chain, :filter_backtrace, :cleaning + end + + def filter_backtrace_with_cleaning(backtrace) + backtrace = filter_backtrace_without_cleaning(backtrace) + backtrace = backtrace.first.split("\n") if backtrace.size == 1 + Rails.backtrace_cleaner.clean(backtrace) + end + end +end
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 347ce6352c..e52dcadd4d 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -62,9 +62,10 @@ class AppGenerator < Rails::Generator::Base m.template "configs/routes.rb", "config/routes.rb" # Initializers - m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" - m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" - m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" + m.template "configs/initializers/backtrace_silencers.rb", "config/initializers/backtrace_silencers.rb" + m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" + m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" + m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" # Locale m.template "configs/locales/en.yml", "config/locales/en.yml" |