File indexing completed on 2024-04-14 04:31:15

0001 /*
0002 * This file is part of KDevelop
0003 *
0004 * Copyright 2007-2010 Alexander Dymo <adymo@kdevelop.org>
0005 * Copyright (C) 2014-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0006 *
0007 * This program is free software; you can redistribute it and/or modify
0008 * it under the terms of the GNU Library General Public License as
0009 * published by the Free Software Foundation; either version 2 of the
0010 * License, or (at your option) any later version.
0011 *
0012 * This program is distributed in the hope that it will be useful,
0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 * GNU General Public License for more details.
0016 *
0017 * You should have received a copy of the GNU General Public
0018 * License along with this program; if not, write to the
0019 * Free Software Foundation, Inc.,
0020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include <rails/helpers.h>
0024 
0025 using namespace KDevelop;
0026 using namespace ruby::rails;
0027 
0028 Path Helpers::findRailsRoot(const QUrl &url)
0029 {
0030     Path current(url.toString());
0031     Path upUrl(current.parent());
0032 
0033     while (upUrl != current) {
0034         Path aux = upUrl.parent();
0035         if (aux.lastPathSegment() == QStringLiteral("app")) {
0036             const QString &dir = upUrl.lastPathSegment();
0037             if (dir == QStringLiteral("controllers") ||
0038                 dir == QStringLiteral("models") ||
0039                 dir == QStringLiteral("views")) {
0040                 return aux.parent();
0041             }
0042         } else if (upUrl.lastPathSegment() == QStringLiteral("test")) {
0043             return aux;
0044         }
0045         current = upUrl;
0046         upUrl = aux;
0047     }
0048     return Path();
0049 }
0050