Sha256: ee0d603ab364f2e529ee2f1895bb980c6e0cce324d6232327b28514902a05cf7

Contents?: true

Size: 717 Bytes

Versions: 2

Compression:

Stored size: 717 Bytes

Contents

module Pulse
  class UserInformer
    def initialize(app)
      @app = app
    end

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

    def call(env)
      status, headers, body = @app.call(env)
      if env['pulse.error_id'] && Pulse.configuration.user_information
        new_body = []
        replace  = replacement(env['pulse.error_id'])
        body.each do |chunk|
          new_body << chunk.gsub("<!-- PULSE 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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
projectlocker_pulse-1.0.0 lib/pulse/user_informer.rb
projectlocker_pulse-0.2.1 lib/pulse/user_informer.rb