-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.rb
54 lines (46 loc) · 1.67 KB
/
site.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# encoding: utf-8
#--
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
class Site < ActiveRecord::Base
has_many :projects
validates_presence_of :title
HTTP_CLONING_SUBDOMAIN = 'git'
validates_exclusion_of :subdomain, :in => [HTTP_CLONING_SUBDOMAIN]
attr_protected :subdomain
def self.default
Site.new(:title => GitoriousConfig["site_name"], :subdomain => nil)
end
def wiki_git_path
repo_name = Site.wiki_repo_name(self.title)
Repository.full_path_from_partial_path(repo_name)
end
def self.wiki_git_path(site_title)
repo_name = Site.wiki_repo_name(site_title)
Repository.full_path_from_partial_path(repo_name)
end
def self.wiki_repo_name(site_title)
"#{site_title}-site-wiki.git"
end
def wiki
if(!File.exist? wiki_git_path)
FileUtils.mkdir_p(wiki_git_path, :mode => 0755)
repo_name = Site.wiki_repo_name(self.title)
Repository.create_git_repository(repo_name)
end
Grit::Repo.new(wiki_git_path)
end
end