Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
59
Help us understand the problem. What is going on with this article?
@izumin5210

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

More than 3 years have passed since last update.

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

# 後略

参考

59
Help us understand the problem. What is going on with this article?
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
izumin5210
ʕ ◔ϖ◔ʔ < I'm a Rubyist.
wantedly
「シゴトでココロオドル」ためのビジネスSNS「Wantedly」の開発・運営をしています。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
59
Help us understand the problem. What is going on with this article?