Class: TaskMapper::Provider::Base::Ticket
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- TaskMapper::Provider::Base::Ticket
- Extended by:
- Helper
- Defined in:
- lib/taskmapper/ticket.rb
Overview
The base ticket class for taskmapper All providers should inherit this class
The difference between the class methods and instance methods are that the instance methods should be treated as though they are called on a known ticket and the class methods act based on a blank slate (which means the info to find a specific ticket has to be passed in the parameters in the ticket)
Methods that the provider should define if feasible:
-
reload!
-
initialize
-
close
-
save
-
destroy
Methods that would probably be okay if the provider left it alone:
-
self.create
-
update
-
update!
-
self.find
A provider should define as many attributes as feasibly possible. The list below are some guidelines as to what attributes are necessary, if your provider’s api does not implement them, point it to an attribute that is close to it. (for example, a title can point to summary. and assignee might point to assigned_to. Remember to alias it in your class!)
-
id
-
status
-
priority
-
title
-
resolution
-
created_at
-
updated_at
-
description
-
assignee
-
requestor
-
project_id
Direct Known Subclasses
Constant Summary collapse
- API =
Replace with your ticket API’s Class
nil
Instance Attribute Summary collapse
-
#system ⇒ Object
Returns the value of attribute system.
-
#system_data ⇒ Object
Returns the value of attribute system_data.
Class Method Summary collapse
-
.find(project_id, *options) ⇒ Object
Find ticket You can also retrieve an array of all tickets by not specifying any query.
-
.find_by_attributes(project_id, attributes = {}) ⇒ Object
Accepts an attributes hash and returns all tickets matching those attributes in an array Should return all tickets if the attributes hash is empty Must be defined by the provider.
-
.find_by_id(project_id, ticket_id) ⇒ Object
Accepts an integer id and returns the single ticket instance Must be defined by the provider.
-
.first(project_id, *options) ⇒ Object
The first of whatever ticket.
-
.last(project_id, *options) ⇒ Object
The last of whatever ticket.
-
.search(project_id, options = {}, limit = 1000) ⇒ Object
This is a helper method to find.
Instance Method Summary collapse
-
#close(*options) ⇒ Object
Close this ticket.
- #comment(*options) ⇒ Object
-
#comment!(*options) ⇒ Object
Create a comment.
-
#comments(*options) ⇒ Object
Asks the provider’s api for the comment associated with the project, returns an array of Comment objects.
-
#reload!(*options) ⇒ Object
Reload this ticket.
Methods included from Helper
easy_finder, filter_string, provider_parent, search_by_attribute, search_filter, this_method
Methods included from Common
#destroy, included, #initialize, #respond_to?, #save, #update!
Instance Attribute Details
#system ⇒ Object
Returns the value of attribute system.
46 47 48 |
# File 'lib/taskmapper/ticket.rb', line 46 def system @system end |
#system_data ⇒ Object
Returns the value of attribute system_data.
46 47 48 |
# File 'lib/taskmapper/ticket.rb', line 46 def system_data @system_data end |
Class Method Details
.find(project_id, *options) ⇒ Object
Find ticket You can also retrieve an array of all tickets by not specifying any query.
-
find(<project_id>) or find(<project_id>, :all) - Returns an array of all tickets
-
find(<project_id>, ##) - Returns a ticket based on that id or some other primary (unique) attribute
-
find(<project_id>, [#, #, #]) - Returns many tickets with these ids
-
find(<project_id>, :first, :title => ‘ticket name’) - Returns the first ticket based on the ticket’s attribute(s)
-
find(<project_id>, :last, :title => ‘Some ticket’) - Returns the last ticket based on the ticket’s attribute(s)
-
find(<project_id>, :all, :title => ‘Test ticket’) - Returns all tickets based on the given attribute(s)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/taskmapper/ticket.rb', line 58 def self.find(project_id, *) first, attributes = if first.nil? or (first == :all and attributes.nil?) self.find_by_attributes(project_id) elsif first.is_a? Array first.collect { |id| self.find_by_id(project_id, id) } elsif first == :first tickets = attributes.nil? ? self.find_by_attributes(project_id) : self.find_by_attributes(project_id, attributes) tickets.first elsif first == :last tickets = attributes.nil? ? self.find_by_attributes(project_id) : self.find_by_attributes(project_id, attributes) tickets.last elsif first == :all self.find_by_attributes(project_id, attributes) else self.find_by_id(project_id, first) end end |
.find_by_attributes(project_id, attributes = {}) ⇒ Object
Accepts an attributes hash and returns all tickets matching those attributes in an array Should return all tickets if the attributes hash is empty Must be defined by the provider
100 101 102 103 104 105 106 |
# File 'lib/taskmapper/ticket.rb', line 100 def self.find_by_attributes(project_id, attributes = {}) if self::API.is_a? Class self.search(project_id, attributes) else raise TaskMapper::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider") end end |
.find_by_id(project_id, ticket_id) ⇒ Object
Accepts an integer id and returns the single ticket instance Must be defined by the provider
89 90 91 92 93 94 95 |
# File 'lib/taskmapper/ticket.rb', line 89 def self.find_by_id(project_id, ticket_id) if self::API.is_a? Class self.new self::API.find(ticket_id, :params => {:project_id => project_id}) else raise TaskMapper::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider") end end |
.first(project_id, *options) ⇒ Object
The first of whatever ticket
78 79 80 |
# File 'lib/taskmapper/ticket.rb', line 78 def self.first(project_id, *) self.find(project_id, :first, *) end |
.last(project_id, *options) ⇒ Object
The last of whatever ticket
83 84 85 |
# File 'lib/taskmapper/ticket.rb', line 83 def self.last(project_id, *) self.find(project_id, :last, *) end |
.search(project_id, options = {}, limit = 1000) ⇒ Object
This is a helper method to find
109 110 111 112 113 114 115 116 |
# File 'lib/taskmapper/ticket.rb', line 109 def self.search(project_id, = {}, limit = 1000) if self::API.is_a? Class tickets = self::API.find(:all, :params => {:project_id => project_id}).collect { |ticket| self.new ticket } search_by_attribute(tickets, , limit) else raise TaskMapper::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider") end end |
Instance Method Details
#close(*options) ⇒ Object
Close this ticket
On success it should return true, otherwise false
143 144 145 |
# File 'lib/taskmapper/ticket.rb', line 143 def close(*) raise TaskMapper::Exception.new("#{self.class.name}::#{this_method} method must be implemented by the provider") end |
#comment(*options) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/taskmapper/ticket.rb', line 126 def comment(*) if .length > 0 .insert(0, project_id) .insert(1, id) end easy_finder(provider_parent(self.class)::Comment, :first, , 2) end |
#comment!(*options) ⇒ Object
Create a comment
135 136 137 138 |
# File 'lib/taskmapper/ticket.rb', line 135 def comment!(*) [0].merge!(:project_id => project_id, :ticket_id => id) if .first.is_a?(Hash) provider_parent(self.class)::Comment.create(*) end |
#comments(*options) ⇒ Object
Asks the provider’s api for the comment associated with the project, returns an array of Comment objects.
120 121 122 123 124 |
# File 'lib/taskmapper/ticket.rb', line 120 def comments(*) .insert 0, project_id .insert 1, id easy_finder(provider_parent(self.class)::Comment, :all, , 2) end |
#reload!(*options) ⇒ Object
Reload this ticket
148 149 150 |
# File 'lib/taskmapper/ticket.rb', line 148 def reload!(*) raise TaskMapper::Exception.new("#{self.class.name}::#{this_method} method must be implemented by the provider") end |