Remove dependency on active support from ProjectPresenter
[gitorious:mainline.git] / app / presenters / project_presenter.rb
1 # encoding: utf-8
2 #--
3 #   Copyright (C) 2012-2013 Gitorious AS
4 #
5 #   This program is free software: you can redistribute it and/or modify
6 #   it under the terms of the GNU Affero General Public License as published by
7 #   the Free Software Foundation, either version 3 of the License, or
8 #   (at your option) any later version.
9 #
10 #   This program is distributed in the hope that it will be useful,
11 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #   GNU Affero General Public License for more details.
14 #
15 #   You should have received a copy of the GNU Affero General Public License
16 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #++
18
19 require 'charlatan'
20
21 class ProjectPresenter
22   include Charlatan.new(:project)
23   private :project
24
25   if instance_methods.include?(:to_param)
26     undef_method :to_param # thank you AS for adding Object#to_param
27   end
28
29   def self.model_name
30     Project.model_name
31   end
32
33   def name
34     title
35   end
36
37   def open_merge_request_count
38     merge_requests.open.count
39   end
40
41   def is_a?(thing)
42     thing == Project
43   end
44
45   def wiki_repository_name
46     wiki_repository.name
47   end
48
49   def feature_enabled?(name)
50     features.include?(name)
51   end
52
53   def owner_to_param_with_prefix
54     owner.to_param_with_prefix
55   end
56
57   def user_to_param_with_prefix
58     user.to_param_with_prefix
59   end
60
61   def short_created_at
62     project.created_at.to_s(:short)
63   end
64
65   def long_created_at
66     project.created_at.to_s(:long)
67   end
68 end