Skip to content

Commit

Permalink
Import Config by jcrosby (Jon Crosby) into core
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Dec 11, 2009
1 parent 5c4bd17 commit a1534a5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack.rb
Expand Up @@ -28,6 +28,7 @@ def self.release
autoload :Chunked, "rack/chunked"
autoload :CommonLogger, "rack/commonlogger"
autoload :ConditionalGet, "rack/conditionalget"
autoload :Config, "rack/config"
autoload :ContentLength, "rack/content_length"
autoload :ContentType, "rack/content_type"
autoload :File, "rack/file"
Expand Down
15 changes: 15 additions & 0 deletions lib/rack/config.rb
@@ -0,0 +1,15 @@
module Rack
# Rack::Config modifies the environment using the block given during
# initialization.
class Config
def initialize(app, &block)
@app = app
@block = block
end

def call(env)
@block.call(env)
@app.call(env)
end
end
end
24 changes: 24 additions & 0 deletions test/spec_rack_config.rb
@@ -0,0 +1,24 @@
require 'test/spec'
require 'rack/mock'
require 'rack/builder'
require 'rack/content_length'
require 'rack/config'

context "Rack::Config" do

specify "should accept a block that modifies the environment" do
app = Rack::Builder.new do
use Rack::Lint
use Rack::ContentLength
use Rack::Config do |env|
env['greeting'] = 'hello'
end
run lambda { |env|
[200, {'Content-Type' => 'text/plain'}, [env['greeting'] || '']]
}
end
response = Rack::MockRequest.new(app).get('/')
response.body.should.equal('hello')
end

end

0 comments on commit a1534a5

Please sign in to comment.