Class: MetaProject::Project::XForge::XForgeBase

Inherits:
Base
  • Object
show all
Defined in:
lib/meta_project/project/xforge/xforge_base.rb

Direct Known Subclasses

RubyForge, SourceForge

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #scm, #scm_web, #tracker

Instance Method Summary collapse

Constructor Details

#initialize(host, unix_name, cvs_mod) ⇒ XForgeBase

Returns a new instance of XForgeBase.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 8

def initialize(host, unix_name, cvs_mod)
  @host = host
  @unix_name = unix_name
  @name = unix_name

  @tracker = tracker_class.new(group_id_uri("tracker"), self)

  unless(cvs_mod.nil?)
    @scm = create_cvs(unix_name, cvs_mod)
    @scm_web = create_view_cvs(unix_name, cvs_mod)
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 6

def host
  @host
end

#unix_nameObject (readonly)

Returns the value of attribute unix_name.



6
7
8
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 6

def unix_name
  @unix_name
end

Instance Method Details

#group_idObject

The group_id of this project



44
45
46
47
48
49
50
51
52
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 44

def group_id
  unless(@group_id)
    html = better_open(xforge_project_url).read
    group_id_pattern = /project\/memberlist.php\?group_id=(\d+)/
    @group_id = html[group_id_pattern, 1]
    raise "Couldn't get group_id from #{xforge_project_url}. I was looking for /#{group_id_pattern.source}/" unless @group_id
  end
  @group_id
end

#group_id_uri(path, postfix = "") ⇒ Object



58
59
60
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 58

def group_id_uri(path, postfix="")
  "http://#{@host}/#{path}/?group_id=#{group_id}#{postfix}"
end

#home_pageObject

The home page of this project



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 63

def home_page
  unless(@home_page)
    html = better_open(xforge_project_url).read
    @home_page = html[home_page_regexp, 1]
    unless @home_page
      STDERR.puts "WARNING: Couldn't get home_page from #{xforge_project_url}. I was looking for /#{home_page_regexp.source}/"
      STDERR.puts "Will use #{xforge_project_url} as home page instead."
      @home_page = xforge_project_url
    end
  end
  @home_page
end

#login(user_name, password) ⇒ Object

Logs in and returns a Session



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 26

def (user_name, password)
  http = Net::HTTP.new(@host, 80)

   = http.start do |http|
    data = [
      "login=1",
      "form_loginname=#{user_name}",
      "form_pw=#{password}"
    ].join("&")
    http.post("/account/login.php", data)
  end

  cookie = ["set-cookie"]
  raise "Login failed" unless cookie
  Session.new(@host, self, cookie)
end

#to_yaml_propertiesObject



21
22
23
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 21

def to_yaml_properties
  ["@host", "@unix_name"]
end

#xforge_project_urlObject



54
55
56
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 54

def xforge_project_url
  "http://#{@host}/projects/#{@unix_name}/"
end