aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gems/rack-1.1.0/lib/rack/builder.rb
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2012-03-12 13:05:19 +0000
committerSeb Bacon <seb.bacon@gmail.com>2012-03-12 13:05:19 +0000
commit37bff4c0154b57b35a3194a9b31a9422496b955b (patch)
tree61592a6bb9d1d9fea378a6e4efa8fdf7d5525b8a /vendor/gems/rack-1.1.0/lib/rack/builder.rb
parent8b49dc894066e452232cabd09333895487f86986 (diff)
parent8acea24f98268fbb9b73b66b9e98a1788a3b30ac (diff)
Merge branch 'merged-bundler' into develop
Diffstat (limited to 'vendor/gems/rack-1.1.0/lib/rack/builder.rb')
-rw-r--r--vendor/gems/rack-1.1.0/lib/rack/builder.rb80
1 files changed, 0 insertions, 80 deletions
diff --git a/vendor/gems/rack-1.1.0/lib/rack/builder.rb b/vendor/gems/rack-1.1.0/lib/rack/builder.rb
deleted file mode 100644
index 530f0aaf0..000000000
--- a/vendor/gems/rack-1.1.0/lib/rack/builder.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-module Rack
- # Rack::Builder implements a small DSL to iteratively construct Rack
- # applications.
- #
- # Example:
- #
- # app = Rack::Builder.new {
- # use Rack::CommonLogger
- # use Rack::ShowExceptions
- # map "/lobster" do
- # use Rack::Lint
- # run Rack::Lobster.new
- # end
- # }
- #
- # Or
- #
- # app = Rack::Builder.app do
- # use Rack::CommonLogger
- # lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] }
- # end
- #
- # +use+ adds a middleware to the stack, +run+ dispatches to an application.
- # You can use +map+ to construct a Rack::URLMap in a convenient way.
-
- class Builder
- def self.parse_file(config, opts = Server::Options.new)
- options = {}
- if config =~ /\.ru$/
- cfgfile = ::File.read(config)
- if cfgfile[/^#\\(.*)/] && opts
- options = opts.parse! $1.split(/\s+/)
- end
- cfgfile.sub!(/^__END__\n.*/, '')
- app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
- TOPLEVEL_BINDING, config
- else
- require config
- app = Object.const_get(::File.basename(config, '.rb').capitalize)
- end
- return app, options
- end
-
- def initialize(&block)
- @ins = []
- instance_eval(&block) if block_given?
- end
-
- def self.app(&block)
- self.new(&block).to_app
- end
-
- def use(middleware, *args, &block)
- @ins << lambda { |app| middleware.new(app, *args, &block) }
- end
-
- def run(app)
- @ins << app #lambda { |nothing| app }
- end
-
- def map(path, &block)
- if @ins.last.kind_of? Hash
- @ins.last[path] = self.class.new(&block).to_app
- else
- @ins << {}
- map(path, &block)
- end
- end
-
- def to_app
- @ins[-1] = Rack::URLMap.new(@ins.last) if Hash === @ins.last
- inner_app = @ins.last
- @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) }
- end
-
- def call(env)
- to_app.call(env)
- end
- end
-end