Daniel Doubrovkine bio photo

Daniel Doubrovkine

aka dB., @awscloud, former CTO @artsy, +@vestris, NYC

Email Twitter LinkedIn Github Strava
Creative Commons License

One of the frequently requested features in Grape to to automatically reload code changes, much like Rails does (#131). This is actually pretty difficult to implement and requires Grape support where an API::reload! method would blow away all of the mounted features, procs, settings, etc.

For bare Rack-mounted applications we can make our life easy with Guard. Introducing guard-rack, which will rackup your Rack application on change. On a decent developer box this just takes a second or two. The implementation is heavily inspired (aka stolen) from guard-rails.

For a typical Rack application, including one that uses Grape, add guard, guard-bundler (to watch Gemfile changes) and guard-rack to Gemfile.

group :development do
  gem "guard"
  gem "guard-bundler"
  gem "guard-rack"
end

Create a Guardfile. Watch the folders of your application.

guard 'bundler' do
  watch('Gemfile')
end

guard 'rack' do
  watch('Gemfile.lock')
  watch(%r{^(config|app|api)/.\*})
end

Run with bundle exec guard. Watch rackup happen every time you change files.

I’ve added this to my grape-on-rack demo.