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.

Returns:

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



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

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

#format_project_listObject

Prepends an asterisk to the current project

Returns:

  • The project list formatted as a printable string



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

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

Parameters:

  • token (defaults to: nil)

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

Returns:

  • the project list



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

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

#project_listObject

Does not do any processing

Returns:

  • The project list if ‘load_project_list’ has been called, else returns nil



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

def project_list
  @project_list
end