Browse Source

pagy + monkeypatcher

main
pvincent 8 months ago
parent
commit
633460e3cf
  1. 1
      Gemfile
  2. 2
      Gemfile.lock
  3. 2
      Procfile.dev
  4. 8
      app/controllers/scores_controller.rb
  5. 3
      app/helpers/pagy_helper.rb
  6. 2
      app/views/scores/index.html.erb
  7. 14
      config/initializers/monkey_patcher.rb
  8. 14
      lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb

1
Gemfile

@ -3,6 +3,7 @@ ruby '3.1.2'
gem 'bootsnap', require: false
gem 'importmap-rails'
gem 'pagy'
gem 'pg'
gem 'puma'
gem 'rackup'

2
Gemfile.lock

@ -147,6 +147,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.4-x86_64-linux)
racc (~> 1.4)
pagy (8.4.0)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
@ -316,6 +317,7 @@ DEPENDENCIES
error_highlight
htmlbeautifier
importmap-rails
pagy
pg
puma
rackup

2
Procfile.dev

@ -1,3 +1,3 @@
web: RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}"
web: TERMINAL_PREFIX=15 RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}"
css: BROWSERSLIST_IGNORE_OLD_DATA=true bundle exec -- rails tailwindcss:watch

8
app/controllers/scores_controller.rb

@ -1,18 +1,22 @@
# ScoresController define Score and Grade interactions
class ScoresController < ApplicationController
include Pagy::Backend
before_action :set_score, only: %i[show edit update destroy]
# GET /scores
def index
@scores = Score.all
@pagy, @scores = pagy(Score.all)
logger.info 'this is a normal message'
logger.info 'this is a super long message which should be wrapped. ' * 5
# logger.info({ one: 1, two: 2 })
# logger.info 'this is an information', { four: 4, five: 5 }
# logger.debug BigDecimal('0.0003')
# logger.warn 'scores are', @scores
# logger.warn 'this is a warning'
# logger.error 'this is an error message'
logger.info 'end of normal message'
# logger.info 'end of normal message'
# logger.debug @scores
# sleep 0.5
end

3
app/helpers/pagy_helper.rb

@ -0,0 +1,3 @@
module PagyHelper
include Pagy::Frontend
end

2
app/views/scores/index.html.erb

@ -8,4 +8,6 @@
<div id="scores" class="min-w-full ">
<%= render @scores %>
</div>
<%== pagy_nav(@pagy) %>
</div>

14
config/initializers/monkey_patcher.rb

@ -0,0 +1,14 @@
return unless defined?(Rails::Server)
puts 'MonkeyPatcher runs:'
patches = Dir.glob(Rails.root.join('lib', 'monkey_patches', '**', '*.rb'))
patches.each do |file|
puts "🐵 patching... #{Pathname.new(file).relative_path_from Rails.root}"
require file
end
puts case patches.count
when 0 then 'No patch found'
when 1 then '1 successful patch applied'
else "#{patches.count} successful patches applied"
end

14
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
Loading…
Cancel
Save