Class: Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/track-r/tracker.rb

Overview

The class is a wrapper for getting projects, stories and using tokens. It’s main purpose is relating the three allowing to interact with a project, and its stories using a token. Expects a token when initialized.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil) ⇒ Tracker

To generate a token, use the “Create New Token” link on the My Profile page (www.pivotaltracker.com/profile).

Raises:

  • (TypeError)


9
10
11
12
# File 'lib/track-r/tracker.rb', line 9

def initialize(token=nil)
  @token = token || Token.new
  raise TypeError unless @token.is_a? Token
end

Class Method Details

.find_local(is_active = nil) ⇒ Object

Uses the ProjectMeta model to find locally stored projects and their api counterparts



42
43
44
45
# File 'lib/track-r/tracker.rb', line 42

def self.find_local(is_active=nil)
  local = ProjectMeta.find_local(is_active)
  local.map{|meta| Tracker.new.find_project{|project| puts "+++#{meta.project_id} == #{project.id}"; meta.project_id == project.id } } unless local.nil? || local.empty?
end

Instance Method Details

#find_projectObject

Receives a block with the condition to find a project. Should work the same as Enumerable.find method Returns a Project object



34
35
36
37
38
39
# File 'lib/track-r/tracker.rb', line 34

def find_project
  get_projects unless defined?(@projects) && @projects.is_a?(Array)
  @projects.find do |project|
    yield(project)
  end
end

#project(project_id) ⇒ Object

Fetches project with given ID Returns a Project object



16
17
18
# File 'lib/track-r/tracker.rb', line 16

def project(project_id)
  @project = Project.new(:project_id => project_id)
end

#projectsObject

Alias for get_projects Returns an array of projects



29
# File 'lib/track-r/tracker.rb', line 29

def projects ; get_projects ; end

#syncObject

Refresh the projects from the server Returns an array of projects



22
23
24
25
# File 'lib/track-r/tracker.rb', line 22

def sync
  @projects = nil
  get_projects
end