Class: CopyTunerClient::CopyrayMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/copy_tuner_client/copyray_middleware.rb

Overview

レスポンス HTML を Rewriter に通し、マーカートークンを data-copyray-key 属性へ変換する Rack middleware

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CopyrayMiddleware

Returns a new instance of CopyrayMiddleware.



8
9
10
# File 'lib/copy_tuner_client/copyray_middleware.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/copy_tuner_client/copyray_middleware.rb', line 12

def call(env)
  CopyTunerClient::TranslationLog.clear
  status, headers, response = @app.call(env)
  if rewritable?(status, headers) && (body = response_body(response))
    rewrite_response(env, status, headers, body, response)
  else
    [status, headers, response]
  end
end