Module: Roda::RodaPlugins::Middleware::ClassMethods

Defined in:
lib/roda/plugins/middleware.rb

Instance Method Summary collapse

Instance Method Details

#new(app, *args, &block) ⇒ Object

Create a Forwarder instead of a new instance if a non-Hash is given.



117
118
119
120
121
122
123
# File 'lib/roda/plugins/middleware.rb', line 117

def new(app, *args, &block)
  if app.is_a?(Hash)
    super
  else
    Forwarder.new(self, app, *args, &block)
  end
end

#route(*args, &block) ⇒ Object

Override the route block so that if no route matches, we throw so that the next middleware is called.



127
128
129
130
131
132
133
# File 'lib/roda/plugins/middleware.rb', line 127

def route(*args, &block)
  super do |r|
    res = instance_exec(r, &block)
    throw :next, true if r.forward_next
    res
  end
end