Class: ActiveRecordMigrationUi::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_migration_ui/middleware.rb

Overview

Intercepts the ActiveRecord::PendingMigrationError and loads the engine’s MigrationsController.

Demystified thanks to aashishgarg.github.io/rails/sample-rack-application/

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



9
10
11
12
# File 'lib/active_record_migration_ui/middleware.rb', line 9

def initialize(app)
  # The next middleware to be called.
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/active_record_migration_ui/middleware.rb', line 14

def call(env)
  if database_needs_migration? && not_ar_migration_ui_request?(env)
    # Pending migration detected, move to the entrypoint controller
    MigrationsController.call(env)
  else
    @app.call(env) # Move to the next middleware (See `rake middleware`)
  end
end