#require 'rack/utils' module Bushido class Middleware BUSHIDO_JS_URL = "#{Bushido::Platform.host}/api/bushido.js" include Rack::Utils def initialize(app, opts = {}) @app = app @bushido_app_name = ENV['BUSHIDO_APP'] @bushido_metrics_token = ENV['BUSHIDO_METRICS_TOKEN'] @bushido_claimed = (ENV['BUSHIDO_CLAIMED'].nil? or ENV['BUSHIDO_CLAIMED'].blank?) ? false : true end def call(env) status, headers, response = @app.call(env) unless @bushido_app_name.empty? content = "" response.each { |part| content += part } # "claiming" bar + stats ? content.gsub!(/<\/body>/i, <<-STR STR ) headers['content-length'] = bytesize(content).to_s end [status, headers, [content]] end end end