60
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Organization

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

続編書いた → 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

# 後略

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
60
Help us understand the problem. What are the problem?