Reputation: 164
I apparently have a Rack::Builder misunderstanding. Inside my config.ru file i've got:
require 'rack'
require 'rack/lobster'
class Shrimp
SHRIMP_STRING = 'teste'
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
response_body = ""
response.each { |part| response_body += part }
response_body += "<pre>#{SHRIMP_STRING}</pre>"
headers["Content-Length"] = response_body.length.to_s
[status, headers, response_body]
end
end
app = Rack::Builder.new do
use Rack::Lobster
run Shrimp.new
end
Rack::Handler::WEBrick.run app
When I do a rackup config.ru
I get a
/home/vagrant/config.ru:7:in `initialize': wrong number of arguments (0 for 1) (ArgumentError)
from /home/vagrant/config.ru:26:in `new'
Am I missing something? According to this tutorial Rack::Builder.new only receives a block as a parameter.
EDIT: changing this line
run Shrimp.new
to:
run Shrimp
I still get a wrong number of arguments, but this time for Rack::Builder
ERROR ArgumentError: wrong number of arguments (1 for 0)
/home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:86:in `initialize'
Upvotes: 0
Views: 900
Reputation: 73649
For Rack middleware, you don't need to do Shrimp.new
, You just need to do use Shrimp
and it should do.
You can find it's one example here.
As par this link you only need to do following:
# config.ru
require 'rack'
require 'rack/lobster'
require 'shrimp'
use Shrimp
run Rack::Lobster.new
Upvotes: 1