66
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Sinatra】オートリロードしてほしい

Last updated at Posted at 2013-12-27

続編書いた → http://qiita.com/izumin5210/items/cbaa99231c031cec8b07


コード変更するたびに再起動は超面倒なので…
Sinatra::Reloaderを使うといいらしい.

つかいかた

導入

とりあえずsinatra-contribを入れる.

Gemfile
# 前略

gem 'sinatra'
gem 'sinatra-contrib'

# 後略

有効化

Classic Application

require 'sinatra/reloader'するだけでOK.
開発環境だけでしか使わないならdevelopment?で判定して読み込ませる.

app.rb
# coding: utf-8
# くらしっくなやつ

require 'sinatra'
require 'sinatra/reloader' if development?

# 後略

Modular Application

require 'sinatra/reloader'は同じ.
オートリロードさせたいクラス内でregister Sinatra::Reloaderすると有効化される.らしい.

app.rb
# coding: utf-8
# もじゅらーなやつ

require "sinatra/base"
require "sinatra/reloader"

class App < Sinatra::Base
  configure :development do
    register Sinatra::Reloader
  end

  # 中略

end

# 後略

参考

66
59
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
66
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?