Skip to content

Instantly share code, notes, and snippets.

@bcaccinolo
Forked from vsizov/gist:4500870
Created July 26, 2018 10:03
Show Gist options
  • Save bcaccinolo/51a2ef0d8abc8532b56c23c0c4f5e59c to your computer and use it in GitHub Desktop.
Save bcaccinolo/51a2ef0d8abc8532b56c23c0c4f5e59c to your computer and use it in GitHub Desktop.
Automatically reload gems in rails 5 on every request in development
# Source: http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
# Inside config/environments/development.rb
# Do the following after every request to the server in development mode
ActionDispatch::Callbacks.to_cleanup do
# If the gem's top level module is currently loaded, unload it
if Object.const_defined?(:MyCoolGem)
Object.send(:remove_const, :MyCoolGem)
end
# Instruct ruby to "unrequire" all of the gems files.
# CAREFUL: make sure this only matches your gems files.
$".delete_if {|s| s.include? "my_cool_gem"}
# Re-require your gem
# Note: because we removed all files previously required they will be reloaded
# even if you didn't use load/autoload in your gem.
require "my_cool_gem"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment