Sha256: 3aa5742a313bd21a532f42be5b4adc63c978610328cf5a0c37bba27108ae2364

Contents?: true

Size: 765 Bytes

Versions: 2

Compression:

Stored size: 765 Bytes

Contents

class Bulletware
  def initialize(app)
    @app = app
  end

  def call(env)
    return @app.call(env) unless Bullet.enable?

    Bullet::Association.start_request
    status, headers, response = @app.call(env)
    return [status, headers, response] if response.empty?

    if Bullet::Association.has_bad_assocations?
      if !headers['Content-Type'].nil? and headers['Content-Type'].include? 'text/html'
        response_body = response.body.insert(-17, Bullet::Association.bad_associations_alert)
        headers['Content-Length'] = response_body.length.to_s
      end

      Bullet::Association.log_bad_associations(env['PATH_INFO'])
    end
    response_body ||= response.body
    Bullet::Association.end_request
    [status, headers, response_body]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flyerhzm-bullet-1.0.0 lib/bulletware.rb
flyerhzm-bullet-1.1.0 lib/bulletware.rb