aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/string_coercion.rb
blob: 232e947835488475ee78a8c83435a1eac7f9ad20 (plain) (tree)




























                                               
module ActionDispatch
  class StringCoercion
    class UglyBody < ActiveSupport::BasicObject
      def initialize(body)
        @body = body
      end

      def each
        @body.each do |part|
          yield part.to_s
        end
      end

      private
        def method_missing(*args, &block)
          @body.__send__(*args, &block)
        end
    end

    def initialize(app)
      @app = app
    end

    def call(env)
      status, headers, body = @app.call(env)
      [status, headers, UglyBody.new(body)]
    end
  end
end