Class: PivotalCli::Tracker
- Inherits:
-
Object
- Object
- PivotalCli::Tracker
- Defined in:
- lib/pivotal_cli/tracker.rb
Instance Attribute Summary collapse
-
#projects ⇒ Object
Returns the value of attribute projects.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #config_file ⇒ Object
- #create_story(story) ⇒ Object
- #find_story(story_id) ⇒ Object
- #load_configuration ⇒ Object
- #my_stories_per_project ⇒ Object
- #set_points(story, points) ⇒ Object
- #setup(username, project_ids, token) ⇒ Object
- #setup_complete? ⇒ Boolean
- #start(story) ⇒ Object
Instance Attribute Details
#projects ⇒ Object
Returns the value of attribute projects.
5 6 7 |
# File 'lib/pivotal_cli/tracker.rb', line 5 def projects @projects end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/pivotal_cli/tracker.rb', line 5 def username @username end |
Instance Method Details
#config_file ⇒ Object
7 8 9 |
# File 'lib/pivotal_cli/tracker.rb', line 7 def config_file @config_file ||= "#{ENV['HOME']}/.pivotal" end |
#create_story(story) ⇒ Object
40 41 42 43 44 |
# File 'lib/pivotal_cli/tracker.rb', line 40 def create_story(story) story.story_type = 'feature' story.owned_by = username story.create # Return a new story object (with id) end |
#find_story(story_id) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/pivotal_cli/tracker.rb', line 31 def find_story(story_id) projects.each do |project| story = project.stories.find(story_id) return story unless story.nil? end nil end |
#load_configuration ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pivotal_cli/tracker.rb', line 54 def load_configuration File.open(config_file, 'r') do |file| lines = file.readlines @username = lines[0].strip token = lines[2].strip project_ids = lines[1].split(',').map(&:strip) PivotalTracker::Client.token = token PivotalTracker::Client.use_ssl = true @projects = project_ids.map { |project_id| PivotalTracker::Project.find(project_id) } end end |
#my_stories_per_project ⇒ Object
24 25 26 27 28 29 |
# File 'lib/pivotal_cli/tracker.rb', line 24 def my_stories_per_project projects.map do |project| stories = project.stories.all(owned_by: username).reject { |s| s.current_state =~ /accepted/ } [project.id, project.name, stories] end end |
#set_points(story, points) ⇒ Object
46 47 48 |
# File 'lib/pivotal_cli/tracker.rb', line 46 def set_points(story, points) story.update(estimate: points) end |
#setup(username, project_ids, token) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pivotal_cli/tracker.rb', line 15 def setup(username, project_ids, token) username = username.strip File.open(config_file, 'w') do |file| file.puts(username) file.puts(project_ids) file.puts(token) end end |
#setup_complete? ⇒ Boolean
11 12 13 |
# File 'lib/pivotal_cli/tracker.rb', line 11 def setup_complete? File.exists?(config_file) end |
#start(story) ⇒ Object
50 51 52 |
# File 'lib/pivotal_cli/tracker.rb', line 50 def start(story) story.update(current_state: 'started') end |