Sha256: 1586a9267a3d45e51914fa9f3883a5884ea15dec3eb7e2a4d60b4aaf18abc132

Contents?: true

Size: 656 Bytes

Versions: 8

Compression:

Stored size: 656 Bytes

Contents

module Raddocs
  class Middleware
    def initialize(app)
      @app = app
      @file_server = Rack::File.new(Raddocs.configuration.docs_dir)
    end

    def call(env)
      if env["HTTP_ACCEPT"] =~ Raddocs.configuration.docs_mime_type
        env = env.merge({ "PATH_INFO" => File.join(env["PATH_INFO"], "index.txt") })
        response = @file_server.call(env)

        if response[0] == 404
          body = "Docs are not available for this resource.\n"
          response = [404, {"Content-Type" => "type/plain", "Content-Length" => body.size.to_s}, [body]]
        end

        response
      else
        @app.call(env)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
raddocs-0.4.0 lib/raddocs/middleware.rb
raddocs-0.3.0 lib/raddocs/middleware.rb
raddocs-0.2.0 lib/raddocs/middleware.rb
raddocs-0.1.4 lib/raddocs/middleware.rb
raddocs-0.1.3 lib/raddocs/middleware.rb
raddocs-0.1.2 lib/raddocs/middleware.rb
raddocs-0.1.1 lib/raddocs/middleware.rb
raddocs-0.1.0 lib/raddocs/middleware.rb