Class: Translate

Inherits:
Object
  • Object
show all
Defined in:
lib/translate/translate.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Translate

Returns a new instance of Translate.



4
5
6
7
8
9
10
# File 'lib/translate/translate.rb', line 4

def initialize(args)
  @base_url = args[:base_url]
  @username = args[:username]
  @password = args[:password]
  @from_workspace_name = args[:from]
  @to_workspace_name = args[:to]
end

Instance Method Details

#dump_oidsObject



54
55
56
57
58
# File 'lib/translate/translate.rb', line 54

def dump_oids
  File.open("TRANSLATED", "w+") do |f|
    Marshal.dump($TRANSLATED, f)
  end
end

#runObject



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
# File 'lib/translate/translate.rb', line 12

def run
  @slm = RallyRestAPI.new(:base_url => @base_url, :username => @username, :password => @password)

  @workspace1 = @slm.user.subscription.workspaces.values.flatten.find { |w| w.name == @from_workspace_name } 
  @workspace2 = @slm.user.subscription.workspaces.values.flatten.find { |w| w.name == @to_workspace_name } 

  raise "No such workspace #{@from_workspace_name}" unless @workspace1
  raise "No such workspace #{@to_workspace_name}" unless @workspace2
  $TRANSLATED[:from] = @from_workspace_name
  $TRANSLATED[:to] = @to_workspace_name

  if File::exists? "TRANSLATED"
    File.open("TRANSLATED", "r") do |f|
	$TRANSLATED = Marshal.load(f)
    end
    puts "Read TRANSLATED"
  end

  # now do the copy
  [:iteration, :release, :story, :defect, :test_case].each do |type|
    @slm.find_all(type, :workspace => @workspace1).each do |o|
	puts "Copying #{o.type} -- #{o.name}"
	o.copy(@workspace2)
    end
  end unless $TRANSLATED[:copy]
  # mark these workspaces as copied
  $TRANSLATED[:copy] = true
  # dump the oids to disk
  dump_oids

  # Now tangle the objects
  [:test_case, :defect].each do |type|
    @slm.find_all(type, :workspace => @workspace1).each do |o|
	puts "Tangle #{o.type} -- #{o.name}"
	o.tangle(@workspace2)
    end
  end unless $TRANSLATED[:tangle]
  
  $TRANSLATED[:tangle] = true
  dump_oids
end