Guard::Shotgun automatically starts and restarts Rack applications (through rackup
) when needed. As useful as Shotgun when developing a Rack app.
Tested on:
If you have answered 'yes' to any of these questions, you may find some use to this plugin.
Please be sure to have Guard installed before continuing.
Install the gem:
gem install guard-shotgun
Or add it to your Gemfile (inside development group):
gem 'guard-shotgun', :git => 'https://github.com/rchampourlier/guard-shotgun.git'
Add guard definition to your Guardfile by running this command:
guard init shotgun
This guard plugin is intended to be used when developing a Rack application, loaded through rackup
.
It allows automatic reloading of your Rack server when a file is changed.
It provides the same service as the Shotgun gem, relying on Guard to watch for your files.
Please read Guard usage doc
For example, to look at the main.rb
file in your application directory, just set this guard:
guard 'shotgun' do
watch('main.rb')
end
Common config
Here we watch Ruby files within the app
and lib
directories, as well as the config.ru
file. We also use Thin as a server instead of the default WEBRick.
guard 'shotgun', :server => 'thin' do
watch %r{^(app|lib)/.*\.rb}
watch 'config.ru'
end
Please read Guard doc for more info about Guardfile DSL.
server
: the name of the server to use. The option is passed to the rackup
command. You may use for example WEBrick
(default), thin
...port
: the port on which to run the server, the option is also passed to the rackup
command.There is currently no spec :S. I intend to write some (won't need much). You may however go to the spec/dummy_app
directory and run:
bundle install
bundle exec guard
This way, you can check it's working correctly. You can play with the spec/dummy_app/app/base_app.rb
file and introduce some bug so that you may see a failing start is correctly handled too.
Killing Rack when reloading on change without waiting for requests to be completed.
Initial release
Help is welcome!
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make.
Romain Champourlier Colin Rymer
This gem has been built from guard-webrick of Fletcher Nichol.