Browse Source

fix monkey_patches

main
pvincent 3 months ago
parent
commit
2190d23ca9
  1. 15
      config/initializers/monkey_patches.rb
  2. 1
      config/initializers/semantic_logger.rb
  3. 3
      lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb
  4. 17
      lib/monkey_patches/monkey_patcher.rb
  5. 2
      lib/monkey_patches/rails_live_reload/watcher.rb

15
config/initializers/monkey_patches.rb

@ -1,12 +1,19 @@
return unless Rails.application.server? || Rails.application.console?
require_relative '../../lib/monkey_patches/monkey_patcher'
MonkeyPatcher.run do |patch|
def grant(patch)
case patch
when 'action_dispatch/middleware/debug_exceptions.rb' then Rails.application.server?
when 'rails_live_reload/watcher.rb' then Rails.application.server? && Rails.env.development?
when /^semantic/ then true
else false
end
end
puts 'MonkeyPatcher runs:'
patches = Dir.glob(Rails.root.join('lib', 'monkey_patches', '**', '*.rb'))
patches.each do |file|
patch = Pathname.new(file).relative_path_from(Rails.root.join('lib', 'monkey_patches')).to_s
next unless grant patch
puts "🐵 patching... #{patch}"
require file
end

1
config/initializers/semantic_logger.rb

@ -9,6 +9,7 @@ Rails.autoloaders.main.on_load('ApplicationController') do
end
Rails.configuration.after_initialize do
Rails.logger.name = 'error_trap'
Semantic::InstrumentationManager.clear
bootstrap = [{ kind: :restored, constant: 'ACTION_VIEW', type: :boolean, old_value: false, new_value: true },

3
lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb

@ -3,7 +3,6 @@ require 'action_dispatch/routing/inspector'
require 'action_view'
module ActionDispatch
module Middleware
# THIS IS A HACK TO unwrap TagWrapError when detected!
# TagWrapError contains a 'tag' for SemanticLogger and the cause itself
class DebugExceptions
@ -11,6 +10,7 @@ module ActionDispatch
def render_exception(request, exception, wrapper)
## PVINCENT's ADDITION for TagWrapError
log_error(request, wrapper)
if exception.is_a?(Semantic::TagWrapError)
backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner')
@ -34,5 +34,4 @@ module ActionDispatch
end
end
end
end
end

17
lib/monkey_patches/monkey_patcher.rb

@ -1,17 +0,0 @@
class MonkeyPatcher
class << self
MONKEY_PATCHES = Rails.root.join('lib', 'monkey_patches')
def run(&)
patches = Dir.glob(MONKEY_PATCHES.join('**', '*.rb'))
patches.each do |patch|
file = Pathname.new(patch).relative_path_from(MONKEY_PATCHES).to_s
next if file == 'monkey_patcher.rb' # filter off its own file!
if !block_given? || yield(file)
puts "🐵 patching... #{file}"
require file
end
end
end
end
end

2
lib/monkey_patches/rails_live_reload/watcher.rb

@ -5,7 +5,7 @@ module RailsLiveReload
@files = {}
@sockets = []
# puts "Watching: #{root}"
# puts "Watching AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: #{root}"
# RailsLiveReload.patterns.each do |pattern, rule|
# puts " #{pattern} => #{rule}"
# end

Loading…
Cancel
Save