AutoReload is a Ruby gem that enhances your Rails development workflow by automatically reloading the browser whenever you save changes to your view files. This functionality mimics the live reloading experience commonly found in frontend frameworks like React, making your development process more efficient and seamless.
- Automatic Browser Reloading: Detects changes in your view files and reloads the browser instantly.
- Seamless Integration: Easily integrates into your Rails application's middleware stack.
- Development Focused: Designed to work in the development environment without affecting production.
Add this line to your application's Gemfile
:
ruby
Copy code
gem 'auto_reload', git: 'https://github.com/puppe1990/auto_reload'
Replace puppe1990
with your actual GitHub username if you have pushed the gem to GitHub. If you've published the gem to RubyGems, you can install it via:
ruby
Copy code
gem 'auto_reload'
Then execute:
bash
Copy code
bundle install
Or install it yourself as:
bash
Copy code
gem install auto_reload
The gem integrates automatically with your Rails application. No additional configuration is required. Simply start your Rails server:
bash
Copy code
rails server
Now, when you edit and save any view file in app/views
, your browser will automatically reload the page, reflecting your changes instantly.
By default, AutoReload watches the app/views
directory for changes. If you need to customize the directories to watch or other settings, you can modify the gem's configuration (if such functionality is implemented).
Note: Currently, the gem watches app/views
by default. Future updates may include customizable configurations.
The AutoReload gem consists of two main components:
- File Watcher: Uses the
listen
gem to monitor changes in your view files. - WebSocket Server: Utilizes
faye-websocket
to establish a WebSocket connection between the server and the browser.
When a file change is detected, a 'reload' message is sent to the browser via WebSocket, triggering a page reload.
To install this gem onto your local machine for development purposes, run:
bash
Copy code
bundle exec rake install
To release a new version:
-
Update the version number in
version.rb
. -
Commit your changes:
bash
Copy code
git commit -am "Bump version to x.x.x"
-
Push to GitHub:
bash
Copy code
git push origin master
-
Publish the gem:
bash
Copy code
gem build auto_reload.gemspec gem push auto_reload-x.x.x.gem
Bug reports and pull requests are welcome on GitHub at https://github.com/puppe1990/auto_reload. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
-
Fork the repository.
-
Create a new branch for your feature or bugfix:
bash
Copy code
git checkout -b my-feature-branch
-
Make your changes.
-
Commit your changes with clear messages:
bash
Copy code
git commit -am "Add new feature"
-
Push to the branch:
bash
Copy code
git push origin my-feature-branch
-
Create a new Pull Request on GitHub.
The gem is available as open source under the terms of the MIT License.