module SinatraSimpleRouter::ClassMethods

Public Instance Methods

match(method, path, klass, action) click to toggle source
# File lib/sinatra_simple_router.rb, line 26
def match(method, path, klass, action)
  if @version
    path = "/#{@version}#{path}"
  end

  send(method, path) do
    begin
      klass.new(self).send(action)
    rescue => e
      handlers = Array(@@rescued_exceptions[e.class.name])
      if handlers.any?
        handlers.map do |handler|
          handler.call(e, klass.new(self))
        end
      else
        raise e
      end
    end
  end
end
rescue_exception(exception, &block) click to toggle source
# File lib/sinatra_simple_router.rb, line 16
def rescue_exception(exception, &block)
  exception_name = exception.name

  if @@rescued_exceptions[exception_name]
    @@rescued_exceptions[exception_name] << block
  else
    @@rescued_exceptions[exception_name] = [block]
  end
end
version(version, &block) click to toggle source
# File lib/sinatra_simple_router.rb, line 47
def version(version, &block)
  @version = version
  instance_eval(&block)
  @version = nil
end