Class: MetaProject::Project::Trac::TracProject

Inherits:
Base
  • Object
show all
Defined in:
lib/meta_project/project/trac/trac_project.rb

Constant Summary collapse

TRAC_VERSION_PATTERN =
/<strong>Trac ([\d\.]+)[^<]*<\/strong>/

Instance Attribute Summary

Attributes inherited from Base

#name, #scm, #tracker

Instance Method Summary collapse

Constructor Details

#initialize(trac_base_url, svn_root_url, svn_path) ⇒ TracProject

Returns a new instance of TracProject.



6
7
8
9
10
11
# File 'lib/meta_project/project/trac/trac_project.rb', line 6

def initialize(trac_base_url, svn_root_url, svn_path)
  @trac_base_url = trac_base_url
  @svn_path = svn_path
  @scm = RSCM::Subversion.new("#{svn_root_url}#{svn_path}", svn_path)
  @tracker = ::MetaProject::Tracker::Trac::TracTracker.new(@trac_base_url)
end

Instance Method Details

#home_pageObject



47
48
49
# File 'lib/meta_project/project/trac/trac_project.rb', line 47

def home_page
  "#{@trac_base_url}/wiki"
end

#scm_webObject



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
# File 'lib/meta_project/project/trac/trac_project.rb', line 15

def scm_web
  unless @scm_web

    front_page = better_open(@trac_base_url).read
    if(front_page =~ TRAC_VERSION_PATTERN)
      version = $1
      # If there is no minor version part, add 0
      version = "#{version}.0" if version =~ /^[\d]+\.[\d]+$/              
      version = version.gsub(/\./, "").to_i
      if(version >= 90)
        html      = "#{@trac_base_url}/browser/#{@svn_path}/\#{path}?rev=\#{revision}"
        raw       = "#{@trac_base_url}/browser/#{@svn_path}/\#{path}?rev=\#{revision}&format=txt"
      else
        html      = "#{@trac_base_url}/file/#{@svn_path}/\#{path}?rev=\#{revision}"
        raw       = "#{@trac_base_url}/file/#{@svn_path}/\#{path}?rev=\#{revision}&format=txt"
      end

      dir                 = "#{@trac_base_url}/browser/#{@svn_path}/\#{path}"
      history             = "#{@trac_base_url}/log/#{@svn_path}/\#{path}"
      diff                = "#{@trac_base_url}/changeset/\#{revision}"
      child_dirs_pattern  = /title="Browse Directory" href="[^"]+">([^<]+)<\/a>/
      child_files_pattern = /title="View File" href="[^"]+">([^<]+)<\/a>/

      @scm_web = ScmWeb::Browser.new(dir, history, raw, html, diff, child_dirs_pattern, child_files_pattern)
    else
      raise ProjectException.new("Couldn't determine the Trac version. Is the URL '#{@trac_base_url}' correct? I was looking for the regexp /#{TRAC_VERSION_PATTERN.source}/ on the page, but couldn't find it.")
    end
  end

  @scm_web
end