
Security News
Oxlint Introduces Type-Aware Linting Preview
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
A dead simple ruby code hot reloader wrap around zeitwerk and listen.
See README for those gems for usage.
Install via Rubygems
$ gem install hot_reloader
OR ...
Add to your Gemfile
gem 'hot_reloader'
Following is a example for use hot_reloader with Roda:
config/environment.rb
For simple use case, you just need pass paths to HotReloader.eager_load
or HotReloader.will_listen
.
# config/environment.rb
require 'bundler'
Bundler.require(:default, ENV.fetch('RACK_ENV', "development"))
require_relative 'application'
paths = ["#{__dir__}/../app", "#{__dir__}/../app/models"]
if ENV['RACK_ENV'] == 'development'
HotReloader.will_listen(*paths)
else
HotReloader.eager_load(*paths)
end
For more advanced case(e.g. you need setup zeitwerk loader instance yourself), you can pass this instance to HotReloader methods too.
# config/environment.rb
require 'bundler'
Bundler.require(:default, ENV.fetch('RACK_ENV', "development"))
require_relative 'application'
loader = Zeitwerk::Loader.new
loader.push_dir("#{__dir__}/../app")
loader.push_dir("#{__dir__}/../app/models")
if ENV['RACK_ENV'] == 'development'
HotReloader.will_listen(loader)
else
HotReloader.eager_load(loader)
end
When you change root directories files(app/.rb or app/models/.rb for above case), all monitored files will be reload.
it is possible to trigger reload from any .rb
files, even this file not follow constant
lookup name convention, and this file folder not add to root directories use push_dir
method.
Following is a example.
# app/app.rb
class App < Roda
plugin :hash_routes
Dir["routes/**/*.rb"].each do |route_file|
load route_file
end
end
# routes/blog.rb
class App
hash_routes.on "blog" do |r|
"blog"
end
end
routes/blog.rb
is not follow constant lookup name convention, so, routes/
folder can't be
add to root directories use push_dir method, but you can always trigger with loader.reload
if routes/blog.rb
was changed, then when app/app.rb
reloaded, it will load the
newest code in routes/blog.rb
from the Dir each loop.
For achieve this, you only need pass listened folders to will_listen method as secondary arg.
loader = Zeitwerk::Loader.new
loader.push_dir("#{__dir__}/../app")
listened_folders = ["#{__dir__}/../routes"]
if ENV['RACK_ENV'] == 'development'
HotReloader.will_listen(loader, listened_folders)
else
HotReloader.eager_load(loader)
end
config.ru
which used to start rack based web server with command rackup -o 0.0.0.0 -p 9393
# config.ru
require_relative './config/environment'
if ENV['RACK_ENV'] == 'development'
run ->(env) { App.call(env) }
else
run App.freeze.app
end
Write whatever application needed initialize code into config/application.rb
# config/application.rb
DB = Sequel.connect(ENV.fetch("#{ENV.fetch('RACK_ENV', "development").upcase}_DATABASE_URL"), timeout: 10000)
Sequel::Model.plugin :timestamps
Sequel.extension :symbol_aref
Add roda code into app/app.rb
# app/app.rb
class App < Roda
articles = ['programming ruby', 'programming rust']
route do |r|
r.post "articles" do
articles << r.params["content"]
"Count: #{articles.count}"
end
r.get "articles" do
articles.join(', ')
end
end
end
Directory structure is like this:
├── app/app.rb
├── config/environment.rb
├── config/application.rb
├── config.ru
├── Gemfile
└── Gemfile.lock
After change code in app.rb, all constant get removed from memory, and app.rb evaluated again!
For a more rich WIP sample project, please check my another project marketbet_crawler.
zeitwerk https://github.com/fxn/zeitwerk
listen https://github.com/guard/listen
gem install --dev hot_reloader
or bundle install
.git checkout -b my-new-feature
.git commit -am 'Add some feature'
.git push origin my-new-feature
.Released under the MIT license, See LICENSE for details.
FAQs
Unknown package
We found that hot_reloader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.