Class: PlanBCD::Rails::Middleware

Inherits:
Object
  • Object
show all
Includes:
ViewHelpers, Rack::Utils
Defined in:
lib/planbcd/rails/middleware.rb

Instance Method Summary collapse

Methods included from ViewHelpers

#pbcd_init

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
# File 'lib/planbcd/rails/middleware.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/planbcd/rails/middleware.rb', line 11

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

  headers = HeaderHash.new(headers)

  if headers['Content-Type'].to_s =~ %r{^text/html;}i && PlanBCD::Rails.configuration.auto_insert
    begin
      response = insert_js(response)
    rescue PlanBCD::Rails::Exception => e
      $stderr.write "Failed to insert planbcd tag: #{e.message}\n"
    end
  end

  [status, headers, response]
end