IT story

각 변경 후 Sinatra가 파일을 자동으로 다시로드하는 방법?

hot-time 2020. 7. 23. 08:02
반응형

각 변경 후 Sinatra가 파일을 자동으로 다시로드하는 방법?


나는 사용하고있다

# my_app.rb
load 'index.rb'

이처럼 서버를 시작

ruby my_app.rb

그러나 색인 페이지에서 변경 한 내용은 다시로드하지 않습니다.
여기에 뭔가가 빠졌습니까?


참고 항목 시나 FAQ를 ,

"변경시 Sinatra 앱을 다시로드하려면 어떻게해야합니까?"

우선, Ruby에서 프로세스 내 코드를 다시로드하는 것은 어렵고 모든 시나리오에 적합한 솔루션을 갖는 것은 기술적으로 불가능합니다.

따라서 프로세스 외부 리로드를 권장합니다.

먼저 재실행 을 설치 하지 않은 경우 설치해야합니다 .

 $ gem install rerun

이제 다음과 같이 Sinatra 앱을 시작하면 :

$ ruby app.rb

다시로드하기 위해해야 ​​할 일은 대신 다음과 같이하십시오.

$ rerun 'ruby app.rb'

예를 들어 랙업을 사용하는 경우 다음을 수행하십시오.

$ 재실행 '랙업'

당신은 아이디어를 얻습니다.

여전히 프로세스 내 재로드를 원하면를 확인하십시오 Sinatra::Reloader.


보석 설치 시나트라 리 로더

require 'sinatra'
require 'sinatra/reloader'

참고 : 수동으로 다시로드 해야하는 사용자 정의 파일이 아닌 Sinatra 핸들러 (및 일부 Sinatra 서버 구성 명령) 만 다시로드합니다.

구년 후 UPD가 : 그것을 사용하여 다른 파일을 다시로드 이미 수 있습니다 것 같아 also_reload, dont_reload그리고 after_reload- https://github.com/sinatra/sinatra/pull/1150


rerun보석을 사용할 수 있습니다 .

gem install rerun
rerun 'ruby app.rb' 

또는 랙업을 사용하는 경우

rerun 'rackup'

보석 설치 시나트라 리 로더

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

class MyApp < Sinatra::Base
  register Sinatra::Reloader

  get '/' do
    "Hello Testing1!"
  end
end

환경 변수를 개발로 설정하고 조건부로 gem을로드 할 수 있습니다.


Passenger Standalone으로 애플리케이션을 실행할 때 tmp/always_restart파일을 작성 하십시오.

$ touch tmp/always_restart.txt

자세한 내용은 승객 설명서 를 참조하십시오.


I like the Shotgun gem. If you're using a modular Sinatra app and have a config.ru file it's easy to run.

shotgun config.ru

Check the gem out here. It's fairly straight forward and no configuration needed.


On Windows, I am using my restart gem for this:

restart ruby my_app.rb

or, with rackup:

restart rackup

See here for more info, hope you find it useful.


You could use guard-rack. Lifted from an article at dblock.org:

Add this to your Gemfile:

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

Then, create a Guardfile at the root of your project with this content:

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

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

Lastly, run Guard, like so: bundle exec guard, and rackup will reload every time.


If you only change your templates sinatra will always rerender them if you set your environment to development:

ruby app.rb -e development

참고URL : https://stackoverflow.com/questions/1247125/how-to-get-sinatra-to-auto-reload-the-file-after-each-change

반응형