Class: ProjectlockerErrata::UserInformer

Inherits:
Object
  • Object
show all
Defined in:
lib/projectlocker_errata/user_informer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ UserInformer

Returns a new instance of UserInformer.



3
4
5
# File 'lib/projectlocker_errata/user_informer.rb', line 3

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
# File 'lib/projectlocker_errata/user_informer.rb', line 11

def call(env)
  status, headers, body = @app.call(env)
  if env['projectlocker_errata.error_id'] && ProjectlockerErrata.configuration.user_information
    new_body = []
    replace  = replacement(env['projectlocker_errata.error_id'])
    body.each do |chunk|
      new_body << chunk.gsub("<!-- PROJECTLOCKER_ERRATA ERROR -->", replace)
    end
    body.close if body.respond_to?(:close)
    headers['Content-Length'] = new_body.sum(&:bytesize).to_s
    body = new_body
  end
  [status, headers, body]
end

#replacement(with) ⇒ Object



7
8
9
# File 'lib/projectlocker_errata/user_informer.rb', line 7

def replacement(with)
  ProjectlockerErrata.configuration.user_information.gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
end