Class: Torque::ProjectManager

Inherits:
Object
  • Object
show all
Defined in:
lib/torque/project/project_manager.rb

Overview

Retrieves the list of Pivotal Tracker projects from the Pivotal API, automates the switching of projects

Instance Method Summary collapse

Constructor Details

#initialize(torque_info_parser = TorqueInfoParser.new) ⇒ ProjectManager

Returns a new instance of ProjectManager.

Parameters:

  • torque_info_parser (defaults to: TorqueInfoParser.new)

    An instance of the TorqueInfoParser class



24
25
26
# File 'lib/torque/project/project_manager.rb', line 24

def initialize(torque_info_parser=TorqueInfoParser.new)
  @torque_info_parser = torque_info_parser
end

Instance Method Details

#current_projectObject

Returns the current project if ‘load_project_list’ has been called and one exists, else returns nil



49
50
51
52
53
# File 'lib/torque/project/project_manager.rb', line 49

def current_project
  @project_list.nil? \
  ? nil
  : @project_list.select{|project| project.current}[0]
end

#format_project_listObject

Formats the project list as a printable string

Prepends an asterisk to the current project



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/torque/project/project_manager.rb', line 59

def format_project_list

  list_str = "PROJECTS\n"
  @project_list.each do |project|
    
    project.current \
      ? list_str += "* " \
      : list_str += "  "
    list_str += "#{project.id} #{project.name}" 
    list_str += "\n"
  end

  list_str
end

#load_project_list(token = nil) ⇒ Object

Requests and processes the project list from the Pivotal Tracker API

Returns the project list

Parameters:

  • token (defaults to: nil)

    A Pivotal Tracker API token (default: Loads token from .torqueinfo.yaml)



34
35
36
37
# File 'lib/torque/project/project_manager.rb', line 34

def load_project_list(token=nil)
  get_project_list(token)
  @project_list
end

#project_listObject

Returns the project list if ‘load_project_list’ has been called, else returns nil

Does not do any processing



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

def project_list
  @project_list
end