middleware
middleware copied to clipboard
Middleware param passing fail
I'm not sure exactly what this issue is (or what to do about it), but for some reason building a stack with a parameter out of a hash dies.
require 'rubygems'
require 'middleware'
class MW1
def initialize(app, value)
@app = app
@value = value
end
def call(env)
puts "before"
@value = @app.call(env)
puts "after"
end
end
@config = {'foo' => 'bar'}
var = @config[:var]
pass = Middleware::Builder.new do
use MW1, var
use MW1, 3
end
pass.call(nil)
fail = Middleware::Builder.new do
use MW1, @config['foo']
use MW1, 3
end
fail.call(nil)
output:
before
before
after
after
fail.rb:28: undefined method `[]' for nil:NilClass (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/middleware-0.1.0/lib/middleware/builder.rb:38:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/middleware-0.1.0/lib/middleware/builder.rb:38:in `initialize'
from fail.rb:27:in `new'
from fail.rb:27
The issue is that the builder uses instance_eval
, which is horrible. I need to fix this to use a regular Ruby block.
I'll keep this issue open until that is fixed.