Class: RailsPendingMigrationErrors::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



13
14
15
# File 'lib/rails_pending_migration_errors/middleware.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_pending_migration_errors/middleware.rb', line 17

def call(env)
  status, headers, response = @app.call(env)
  response_body = nil

  return [status, headers, response] unless html_request?(headers, response)

  if RailsPendingMigrationErrors.needs_migrations?
    if RailsPendingMigrationErrors.page_load
      raise ActiveRecord::PendingMigrationError

    else
      response_body = append_response_body(headers, response)

    end
  end

  [status, headers, response_body ? [response_body] : response]
end