Class: Toy::Middleware::IdentityMap

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ IdentityMap

Returns a new instance of IdentityMap.



6
7
8
# File 'lib/toy/middleware/identity_map.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/toy/middleware/identity_map.rb', line 10

def call(env)
  Toy::IdentityMap.clear
  enabled = Toy::IdentityMap.enabled
  Toy::IdentityMap.enabled = true

  response = @app.call(env)
  response[2] = Rack::BodyProxy.new(response[2]) {
    Toy::IdentityMap.enabled = enabled
    Toy::IdentityMap.clear
  }
  response
end