{"id":16086135,"url":"https://github.com/zw963/hot_reloader","last_synced_at":"2025-03-17T17:30:44.538Z","repository":{"id":56876665,"uuid":"176884035","full_name":"zw963/hot_reloader","owner":"zw963","description":"A dead simple ruby code hot reloader wrap around zeitwerk and listen.","archived":false,"fork":false,"pushed_at":"2023-02-09T19:27:00.000Z","size":32,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-10T13:11:06.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zw963.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-21T06:32:57.000Z","updated_at":"2024-08-07T15:43:06.000Z","dependencies_parsed_at":"2024-10-09T13:10:43.969Z","dependency_job_id":"18829d28-8606-48d4-8f03-8dfb2a25bfc3","html_url":"https://github.com/zw963/hot_reloader","commit_stats":{"total_commits":65,"total_committers":1,"mean_commits":65.0,"dds":0.0,"last_synced_commit":"670c67166a8a7df31c8f5e78c972c2777e942681"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zw963%2Fhot_reloader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zw963%2Fhot_reloader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zw963%2Fhot_reloader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zw963%2Fhot_reloader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zw963","download_url":"https://codeload.github.com/zw963/hot_reloader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221697392,"owners_count":16865619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T13:10:37.189Z","updated_at":"2024-10-27T15:19:55.648Z","avatar_url":"https://github.com/zw963.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HotReloader [![CI](https://github.com/zw963/hot_reloader/actions/workflows/ci.yml/badge.svg)](https://github.com/zw963/hot_reloader/actions/workflows/ci.yml) [![Gem Version](https://badge.fury.io/rb/hot_reloader.svg)](http://badge.fury.io/rb/hot_reloader) ![](https://ruby-gem-downloads-badge.herokuapp.com/hot_reloader?type=total)\n\nA dead simple ruby code hot reloader wrap around [zeitwerk](https://github.com/fxn/zeitwerk) and [listen](https://github.com/guard/listen).\n\nSee README for those gems for usage.\n\n## Getting Started\n\nInstall via Rubygems\n\n    $ gem install hot_reloader\n\nOR ...\n\nAdd to your Gemfile\n\n    gem 'hot_reloader'\n\n## Usage\n\nFollowing is a example for use hot_reloader with [Roda](https://github.com/jeremyevans/roda):\n\n### Add loader initialize code into `config/environment.rb`\n\nFor simple use case, you just need pass paths to `HotReloader.eager_load` or `HotReloader.will_listen`.\n\n```rb\n# config/environment.rb\n\nrequire 'bundler'\nBundler.require(:default, ENV.fetch('RACK_ENV', \"development\"))\nrequire_relative 'application'\n\npaths = [\"#{__dir__}/../app\", \"#{__dir__}/../app/models\"]\n\nif ENV['RACK_ENV'] == 'development'\n  HotReloader.will_listen(*paths)\nelse\n  HotReloader.eager_load(*paths)\nend\n```\n\nFor more advanced case(e.g. you need setup zeitwerk loader instance yourself), you\ncan pass this instance to HotReloader methods too.\n\n```rb\n# config/environment.rb\n\nrequire 'bundler'\nBundler.require(:default, ENV.fetch('RACK_ENV', \"development\"))\nrequire_relative 'application'\n\nloader = Zeitwerk::Loader.new\nloader.push_dir(\"#{__dir__}/../app\")\nloader.push_dir(\"#{__dir__}/../app/models\")\n\nif ENV['RACK_ENV'] == 'development'\n  HotReloader.will_listen(loader)\nelse\n  HotReloader.eager_load(loader)\nend\n```\n\nWhen you change root directories files(app/*.rb or app/models/*.rb for above case), \nall monitored files will be reload.\n\nit is possible to trigger reload from any `.rb` files, even this file not follow constant \nlookup name convention, and this file folder not add to root directories use `push_dir` method.\n\nFollowing is a example.\n\n```rb\n# app/app.rb\n\nclass App \u003c Roda\n  plugin :hash_routes\n  \n  Dir[\"routes/**/*.rb\"].each do |route_file|\n    load route_file\n  end\nend\n```\n\n```rb\n# routes/blog.rb\n\nclass App\n  hash_routes.on \"blog\" do |r|\n    \"blog\"\n  end\nend\n```\n\n`routes/blog.rb` is not follow constant lookup name convention, so, `routes/` folder can't be\nadd to root directories use push_dir method, but you can always trigger with `loader.reload`\nif `routes/blog.rb` was changed, then when `app/app.rb` reloaded, it will load the\nnewest code in `routes/blog.rb` from the Dir each loop.\n\nFor achieve this, you only need pass listened folders to will_listen method as secondary arg.\n\n```rb\nloader = Zeitwerk::Loader.new\nloader.push_dir(\"#{__dir__}/../app\")\n\nlistened_folders = [\"#{__dir__}/../routes\"]\n\nif ENV['RACK_ENV'] == 'development'\n  HotReloader.will_listen(loader, listened_folders)\nelse\n  HotReloader.eager_load(loader)\nend\n```\n\n### Add other app files\n\n`config.ru` which used to start rack based web server with `command rackup -o 0.0.0.0 -p 9393`\n\n```rb\n# config.ru\n\nrequire_relative './config/environment'\n\nif ENV['RACK_ENV'] == 'development'\n  run -\u003e(env) { App.call(env) }\nelse\n  run App.freeze.app\nend\n```\n\nWrite whatever application needed initialize code into config/application.rb\n\n```rb\n# config/application.rb\n\nDB = Sequel.connect(ENV.fetch(\"#{ENV.fetch('RACK_ENV', \"development\").upcase}_DATABASE_URL\"), timeout: 10000)\nSequel::Model.plugin :timestamps\nSequel.extension :symbol_aref\n```\n\nAdd roda code into app/app.rb\n\n```rb\n# app/app.rb\n\nclass App \u003c Roda\n  articles = ['programming ruby', 'programming rust']\n  route do |r|\n    r.post \"articles\" do\n      articles \u003c\u003c r.params[\"content\"]\n      \"Count: #{articles.count}\"\n    end\n\t\n\tr.get \"articles\" do\n      articles.join(', ')\n    end\n  end\nend\n```\n\nDirectory structure is like this:\n\n```\n├── app/app.rb\n├── config/environment.rb\n├── config/application.rb\n├── config.ru\n├── Gemfile\n└── Gemfile.lock\n```\n\nAfter change code in app.rb, **all constant get removed from memory, and app.rb evaluated again**!\n\nFor a more rich WIP sample project, please check my another project [marketbet_crawler](https://github.com/zw963/marketbet_crawler).\n\n## Support\n\n  * MRI 2.5+\n  * JRuby\n\n## Dependency\n\n[zeitwerk](https://github.com/fxn/zeitwerk) https://github.com/fxn/zeitwerk\n\n[listen](https://github.com/guard/listen) https://github.com/guard/listen\n\n## Contributing\n\n  * [Bug reports](https://github.com/zw963/hot_reloader/issues)\n  * [Source](https://github.com/zw963/hot_reloader)\n  * Patches:\n    * Fork on Github.\n    * Run `gem install --dev hot_reloader` or `bundle install`.\n    * Create your feature branch: `git checkout -b my-new-feature`.\n    * Commit your changes: `git commit -am 'Add some feature'`.\n    * Push to the branch: `git push origin my-new-feature`.\n    * Send a pull request :D.\n\n## license\n\nReleased under the MIT license, See [LICENSE](https://github.com/zw963/hot_reloader/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzw963%2Fhot_reloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzw963%2Fhot_reloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzw963%2Fhot_reloader/lists"}