Sinatra::Request#process_route(pattern, keys, conditions)

    # If the current request matches pattern and conditions, fill params
    # with keys and call the given block.
    # Revert params afterwards.
    #   
    # Returns pass block.
    def process_route(pattern, keys, conditions)
      @original_params ||= @params
      route = @request.route
      route = '/' if route.empty? and not settings.empty_path_info?
      if match = pattern.match(route)
        values = match.captures.to_a
        params =
          if keys.any?
            keys.zip(values).inject({}) do |hash,(k,v)|
              if k == 'splat'
                (hash[k] ||= []) << v
              else
                hash[k] = v
              end
              hash
            end
          elsif values.any?
            {'captures' => values}
          else
            {}
          end
        @params = @original_params.merge(params)
        @block_params = values
        catch(:pass) do
          conditions.each { |cond|
            throw :pass if instance_eval(&cond) == false }
          yield
        end
      end
    ensure
      @params = @original_params
    end

你可能感兴趣的:(Condition)