Class: TaskMapper::Provider::Base::Project

Inherits:
Hashie::Mash
  • Object
show all
Extended by:
Helper
Includes:
Common, Helper
Defined in:
lib/taskmapper/project.rb

Overview

This is the base Project class for providers

Providers should inherit this class and redefine the methods

Each provider should have their own @system defined. For example, taskmapper-unfuddle’s @system is :unfuddle and taskmapper-lighthouse’s Methods that must be implemented by the provider

  • self.find_by_id

  • self.find_by_attributes

Methods that might need to be implemented by the provider

  • tickets

  • ticket

  • initialize

  • update

  • destroy

  • self.create

Methods that would probably be okay if the provider left it alone:

  • self.find - although you can define your own to optimize it a bit

  • update!

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 name can point to title. Remember to alias it in your class!)

  • id

  • name

  • created_at

  • updated_at

  • description

Direct Known Subclasses

Dummy::Project, Tester::Project

Constant Summary collapse

API =

Replace with your api digestor’s class.

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

easy_finder, filter_string, provider_parent, search_by_attribute, search_filter, this_method

Methods included from Common

#destroy, included, #respond_to?, #save, #update!

Constructor Details

#initialize(*options) ⇒ Project

Define some provider specific initalizations



138
139
140
141
# File 'lib/taskmapper/project.rb', line 138

def initialize(*options)
  # @system_data = {'some' => 'data}
  super(*options)
end

Instance Attribute Details

#systemObject

Returns the value of attribute system.



43
44
45
# File 'lib/taskmapper/project.rb', line 43

def system
  @system
end

#system_dataObject

Returns the value of attribute system_data.



43
44
45
# File 'lib/taskmapper/project.rb', line 43

def system_data
  @system_data
end

Class Method Details

.find(*options) ⇒ Object

Find project You can also retrieve an array of all projects by not specifying any query.

  • find() or find(:all) - Returns an array of all projects

  • find(##) - Returns a project based on that id or some other primary (unique) attribute

  • find([#, #, #]) - Returns many projects with these ids

  • find(:first, :name => ‘Project name’) - Returns the first project based on the project’s attribute(s)

  • find(:last, :name => ‘Some project’) - Returns the last project based on the project’s attribute(s)

  • find(:all, :name => ‘Test Project’) - Returns all projects based on the given attribute(s)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/taskmapper/project.rb', line 55

def self.find(*options)
  first = options.shift
  attributes = options.shift
  if first.nil? or (first == :all and attributes.nil?)
    self.find_by_attributes
  elsif first.is_a? Array
    first.collect { |id| self.find_by_id(id) }
  elsif first == :first
    projects = attributes.nil? ? self.find_by_attributes : self.find_by_attributes(attributes)
    projects.first
  elsif first == :last
    projects = attributes.nil? ? self.find_by_attributes : self.find_by_attributes(attributes)
    projects.last
  elsif first == :all
    self.find_by_attributes(attributes)
  else
    self.find_by_id(first)
  end
end

.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 Must be defined by the provider



98
99
100
101
102
103
104
# File 'lib/taskmapper/project.rb', line 98

def self.find_by_attributes(attributes = {})
  if self::API.is_a? Class
    self.search(attributes)
  else
    raise TaskMapper::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider")
  end
end

.find_by_id(id) ⇒ Object

Accepts an integer id and returns the single project instance Must be defined by the provider



87
88
89
90
91
92
93
# File 'lib/taskmapper/project.rb', line 87

def self.find_by_id(id)
  if self::API.is_a? Class
    self.new self::API.find(id)
  else
    raise TaskMapper::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider")
  end
end

.first(*options) ⇒ Object

The first of whatever project



76
77
78
# File 'lib/taskmapper/project.rb', line 76

def self.first(*options)
  self.find(:first, *options)
end

.last(*options) ⇒ Object

The last of whatever project



81
82
83
# File 'lib/taskmapper/project.rb', line 81

def self.last(*options)
  self.find(:last, *options)
end

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

This is a helper method to find



107
108
109
110
111
112
113
114
# File 'lib/taskmapper/project.rb', line 107

def self.search(options = {}, limit = 1000)
  if self::API.is_a? Class
    projects = self::API.find(:all).collect { |project| self.new project }
    search_by_attribute(projects, options, limit)
  else
    raise TaskMapper::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider")
  end
end

Instance Method Details

#ticket(*options) ⇒ Object

Very similar to tickets, and is practically an alias of it however this returns the ticket class if no parameter is given unlike tickets which returns an array of all tickets when given no parameters



126
127
128
129
# File 'lib/taskmapper/project.rb', line 126

def ticket(*options)
  options.insert(0, id) if options.length > 0
  easy_finder(provider_parent(self.class)::Ticket, :first, options, 1)
end

#ticket!(*options) ⇒ Object

Create a ticket



132
133
134
135
# File 'lib/taskmapper/project.rb', line 132

def ticket!(*options)
  options[0].merge!(:project_id => id) if options.first.is_a?(Hash)
  provider_parent(self.class)::Ticket.create(*options)
end

#tickets(*options) ⇒ Object

Asks the provider’s api for the tickets associated with the project, returns an array of Ticket objects.



118
119
120
121
# File 'lib/taskmapper/project.rb', line 118

def tickets(*options)
  options.insert 0, id
  easy_finder(provider_parent(self.class)::Ticket, :all, options, 1)
end