Class: Gister::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/gister/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, fetcher = Fetcher.new) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
10
# File 'lib/gister/middleware.rb', line 7

def initialize(app, fetcher=Fetcher.new)
  @app = app
  @fetcher = fetcher
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/gister/middleware.rb', line 12

def call(env)
  request = Rack::Request.new env
  if request.path =~ /^\/gist\/([A-Za-z\-0-9]+\/)?[0-9]+.json/
    respond_to_failures do
      [200, {'Content-Type' => 'application/javascript'}, [get_body_content(request)]]
    end
  else
    @app.call(env)
  end
end