略過內容 略過搜尋

如果將 config.active_record.migration_error 設為 :page_load,將使用這個類別來驗證在載入網頁之前是否已執行所有遷移。

方法
C
N

類別公開的方法

new(app, file_watcher: ActiveSupport::FileUpdateChecker)

# File activerecord/lib/active_record/migration.rb, line 649
def initialize(app, file_watcher: ActiveSupport::FileUpdateChecker)
  @app = app
  @needs_check = true
  @mutex = Mutex.new
  @file_watcher = file_watcher
end

實例公開的方法

call(env)

# File activerecord/lib/active_record/migration.rb, line 656
def call(env)
  @mutex.synchronize do
    @watcher ||= build_watcher do
      @needs_check = true
      ActiveRecord::Migration.check_pending_migrations
      @needs_check = false
    end

    if @needs_check
      @watcher.execute
    else
      @watcher.execute_if_updated
    end
  end

  @app.call(env)
end