Class: Translate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TranslationAudit

#all_copied_fields_should_match_for, #audit, #audit_counts, #compare_each, #copy_exists?, #diff_objects, #diff_string, #equal_ignore_whitespace_and_scheduling, #normalized_string

Constructor Details

#initialize(args) ⇒ Translate

Returns a new instance of Translate.



10
11
12
13
14
15
16
17
18
# File 'lib/translate/translate.rb', line 10

def initialize(args)
  @base_url = args[:base_url]
  @username = args[:username]
  @password = args[:password]
  @from_workspace_name = args[:from_workspace]
  @to_workspace_name = args[:to_workspace]
  @logger = args[:logger] if args[:logger]
#    @logger.level = Logger::DEBUG
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/translate/translate.rb', line 8

def logger
  @logger
end

Instance Method Details

#allowed?(type) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/translate/translate.rb', line 74

def allowed?(type)
  @from_workspace.type_definitions.find { |td| td.name == type }
end

#allowed_copy_typesObject



60
61
62
63
64
65
# File 'lib/translate/translate.rb', line 60

def allowed_copy_types
  types = [:iteration, :release, :feature, :use_case, :supplemental_requirement, :story, :defect, :test_case]
  types.delete :test_case unless allowed? "Test Case"
  types.delete :defect unless allowed? "Defect"
  types
end

#allowed_tangle_typesObject



67
68
69
70
71
72
# File 'lib/translate/translate.rb', line 67

def allowed_tangle_types
  types = [:test_case, :defect]
  types.delete :test_case unless allowed? "Test Case"
  types.delete :defect unless allowed? "Defect"
  types
end

#runObject



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
55
56
57
58
# File 'lib/translate/translate.rb', line 20

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

  @from_workspace = @slm.user.subscription.workspaces.find { |w| w.name == @from_workspace_name } 
  @to_workspace = @slm.user.subscription.workspaces.find { |w| w.name == @to_workspace_name } 

  raise "No such workspace #{@from_workspace_name}" unless @from_workspace
  raise "No such workspace #{@to_workspace_name}" unless @to_workspace

  store = TranslationStore.instance(@from_workspace, @to_workspace)

  begin 
    # now do the copy
    allowed_copy_types.each do |type|
	@slm.find_all(type, :workspace => @from_workspace, :order => [:creation_date]).each do |o|
 o.copy(@to_workspace)
	end
    end unless store.copy_finished?
    store.copy_finished!
    @logger.info "Copy complete. "

    # Now tangle the objects
    allowed_tangle_types.each  do |type|
	@slm.find_all(type, :workspace => @from_workspace).each do |o|
 o.tangle(@to_workspace)
	end
    end unless store.tangle_finished?
    store.tangle_finished!
    @logger.info "Tangle complete!"
    @logger.info "Translation complete. Now run with the -a flag to audit the workspace."
  rescue Exception => e
    @logger.warn "Caught an exception #{e}. Remembering where we were."
    @logger.warn e.backtrace.join("\n")
    # Remember where we were if there was a failure
    store.dump
    raise e
  end
end