LoginSignup
7
7

More than 5 years have passed since last update.

Sinatra::Reloader がファイルをリロードするタイミングにフックする

Last updated at Posted at 2014-07-03

なんでこんなことをやりたかったか忘れたが書いたのでメモっておく。

app.rb
require 'sinatra'
require 'sinatra/reloader' if development?

module Sinatra
  module Reloader
    module WatcherExt
      def updated
        updated_files = super
        do_something unless updated_files.empty?
        updated_files
      end

      def do_something
        # Do whatever you want.
      end
    end
  end
end

if Sinatra::Reloader::const_defined?('Watcher')
  klass = Sinatra::Reloader::const_get('Watcher')
  klass.prepend(Sinatra::Reloader::WatcherExt)
end

get '/' do
  ...
end
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7