Class: Talkable::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



6
7
8
# File 'lib/talkable/middleware.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
22
23
24
# File 'lib/talkable/middleware.rb', line 10

def call(env)
  request = Rack::Request.new(env)
  uuid = talkable_visitor_uuid(request)

  result = Talkable.with_uuid_and_url(uuid, request.url) do
    @app.call(env)
  end

  inject_uuid_in_cookie(uuid, result)
  modify_response_content(result) do |content|
    content = inject_uuid_in_body(uuid, content)
    inject_integration_js_in_head(content)
  end

end