From 2e77009d53f889d59972a8ffb2132eb54989f37d Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 6 Apr 2024 00:19:45 +0400 Subject: [PATCH] monkey_patcher --- Gemfile | 1 - Gemfile.lock | 7 ------- config/initializers/monkey_patcher.rb | 15 +++++++++++++++ .../rails_semantic_logger/debug_exceptions.rb | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 config/initializers/monkey_patcher.rb create mode 100644 lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb diff --git a/Gemfile b/Gemfile index f3ca626..9dc2b69 100644 --- a/Gemfile +++ b/Gemfile @@ -29,7 +29,6 @@ group :development do gem 'rubocop-shopify' gem 'rubocop-thread_safety' gem 'ruby-lsp-rails' - gem 'web-console' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 6ed7fba..169ae98 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,7 +81,6 @@ GEM ast (2.4.2) base64 (0.2.0) bigdecimal (3.1.7) - bindex (0.8.1) bootsnap (1.18.3) msgpack (~> 1.2) builder (3.2.4) @@ -313,11 +312,6 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) - web-console (4.2.1) - actionview (>= 6.0.0) - activemodel (>= 6.0.0) - bindex (>= 0.4.0) - railties (>= 6.0.0) webrick (1.8.1) websocket (1.2.10) websocket-driver (0.7.6) @@ -363,7 +357,6 @@ DEPENDENCIES stimulus-rails tailwindcss-rails turbo-rails - web-console RUBY VERSION ruby 3.1.2p20 diff --git a/config/initializers/monkey_patcher.rb b/config/initializers/monkey_patcher.rb new file mode 100644 index 0000000..075b9f8 --- /dev/null +++ b/config/initializers/monkey_patcher.rb @@ -0,0 +1,15 @@ +return unless defined?(Rails::Server) + +logger = SemanticLogger['MonkeyPatcher'] + +patches = Dir.glob(Rails.root.join('lib', 'monkey_patches', '**', '*.rb')) +patches.each do |file| + logger.info "patching... #{Pathname.new(file).relative_path_from Rails.root}" + require file +end + +case patches.count +when 0 then logger.info '== No patch found ==' +when 1 then logger.info '== 1 successful patch applied ==' +else logger.info "== #{count} successful patch applied ==" +end diff --git a/lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb b/lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb new file mode 100644 index 0000000..3657a85 --- /dev/null +++ b/lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb @@ -0,0 +1,14 @@ +require 'rails_semantic_logger/extensions/action_dispatch/debug_exceptions' + +module ActionDispatch + # patched class to prevent deprecated message + class DebugExceptions + private + + def log_error(_request, wrapper) + Rails.application.deprecators.silence do + ActionController::Base.logger.fatal(wrapper.exception) + end + end + end +end