Class: TaskMapper::Provider::Rally::Project

Inherits:
Base::Project
  • Object
show all
Defined in:
lib/provider/project.rb

Overview

Project class for taskmapper-rally

Remaps

id => oid created_at => creation_date updated_at => creation_date

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Project

Returns a new instance of Project.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/provider/project.rb', line 12

def initialize(*object)
  if object.first
    project = object.first
    # Store Rally Project object in taskmapper Project object
    # This allows taskmapper to perform updates on Rally Project
    @system_data = {:client => project}
    hash = {:oid => project.oid, 
            :name => project.name, 
            :description => project.description,
            :created_at => project.creation_date, 
            # Rally Project object does not have a modified time
            :updated_at => project.creation_date}           
    super hash
  end
end

Class Method Details

.find_by_attributes(attributes = {}) ⇒ Object

Accepts an attributes hash and returns all projects matching those attributes in an array Should return all projects if the attributes hash is empty



59
60
61
# File 'lib/provider/project.rb', line 59

def self.find_by_attributes(attributes = {})
  self.search(attributes)
end

.find_by_id(id) ⇒ Object

Accepts an integer id and returns the single project instance



50
51
52
53
54
55
# File 'lib/provider/project.rb', line 50

def self.find_by_id(id)
  # Rally Ruby REST API expects IDs as strings
  # For id.to_s see note on Project::id
  query_result = TaskMapper::Provider::Rally.rally.find(:project, :fetch => true) { equal :object_i_d, id.to_s }
  self.new query_result.first
end

.search(options = {}, limit = 1000) ⇒ Object

This is a helper method to find



64
65
66
67
68
69
# File 'lib/provider/project.rb', line 64

def self.search(options = {}, limit = 1000)
  projects = TaskMapper::Provider::Rally.rally.find_all(:project).collect do |project| 
    self.new project
  end
  search_by_attribute(projects, options, limit)
end

Instance Method Details

#copy(project) ⇒ Object

copy from this.copy(that) copies that into this



72
73
74
75
76
77
78
79
80
# File 'lib/provider/project.rb', line 72

def copy(project)
  project.tickets.each do |ticket|
    copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
    ticket.comments.each do |comment|
      copy_ticket.comment!(:body => comment.body)
      sleep 1
    end
  end
end

#created_atObject



28
29
30
# File 'lib/provider/project.rb', line 28

def created_at
  Time.parse(self[:created_at])
end

#idObject

Rally REST API aliases String and Fixnum :to_q :to_s However, it does not alias Bignum If a ID is a Bignum, the API will throw undefined method Because of this, we pass all IDs to API as strings taskmapper specs set IDs as integers, so coerce type on get



41
42
43
# File 'lib/provider/project.rb', line 41

def id
  self[:oid].to_i
end

#id=(id) ⇒ Object



45
46
47
# File 'lib/provider/project.rb', line 45

def id=(id)
  self[:oid] = id.to_s
end

#updated_atObject



32
33
34
# File 'lib/provider/project.rb', line 32

def updated_at
  Time.parse(self[:updated_at])
end