5 changed files with 38 additions and 48 deletions
-
15config/initializers/monkey_patches.rb
-
1config/initializers/semantic_logger.rb
-
51lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb
-
17lib/monkey_patches/monkey_patcher.rb
-
2lib/monkey_patches/rails_live_reload/watcher.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,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 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue