Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #27 from levent/user_story-state
Browse files Browse the repository at this point in the history
[refactor] simple pullout of horrendous state methods
  • Loading branch information
levent committed Feb 8, 2015
2 parents ea7b648 + 8047370 commit 963ef7d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 68 deletions.
69 changes: 1 addition & 68 deletions app/models/user_story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class UserStory < ActiveRecord::Base
include ElasticSearchable
include Formatters
include SprintPlannable
include State

mapping do
indexes :id, index: :not_analyzed
Expand Down Expand Up @@ -59,62 +60,6 @@ def stakeholder
super.blank? ? person.try(:name) : super
end

def status
cached_status = REDIS.get("user_story:#{self.id}:status")
unless cached_status
if self.inprogress?
cached_status = "inprogress"
elsif self.complete?
cached_status = "complete"
else
cached_status = "incomplete"
end
REDIS.set("user_story:#{self.id}:status", cached_status)
REDIS.expire("user_story:#{self.id}:status", REDIS_EXPIRY)
end
cached_status
end

def inprogress?
if !tasks.blank?
tasks.each do |task|
return true if task.inprogress?
end
return false
else
return false
end
end

def complete?
if !tasks.blank?
tasks.each do |task|
return false unless task.done?
end
return true
else
return false
end
end

def state
cached_state = REDIS.get("user_story:#{self.id}:state")
unless cached_state
if self.cannot_be_estimated?
cached_state = 'clarify'
elsif self.acceptance_criteria.blank?
cached_state = 'criteria'
elsif self.story_points.blank?
cached_state = 'estimate'
else
cached_state = 'plan'
end
REDIS.set("user_story:#{self.id}:state", cached_state)
REDIS.expire("user_story:#{self.id}:state", REDIS_EXPIRY)
end
cached_state
end

def copy!
us = clone_story!
self.acceptance_criteria.each do |ac|
Expand All @@ -138,18 +83,6 @@ def clone_story!
new_us
end

def expire_status
REDIS.del("user_story:#{self.id}:status")
end

def expire_state
REDIS.del("user_story:#{self.id}:state")
end

def expire_story_points
REDIS.del("project:#{self.project.id}:story_points")
end

def expire_sprint_story_points
sprint.try(:expire_total_story_points)
sprints.map(&:expire_total_story_points)
Expand Down
76 changes: 76 additions & 0 deletions app/models/user_story/state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module UserStory::State

# State on task board
# TODO: Redo for clarity
def status
cached_status = REDIS.get("user_story:#{self.id}:status")
unless cached_status
if self.inprogress?
cached_status = "inprogress"
elsif self.complete?
cached_status = "complete"
else
cached_status = "incomplete"
end
REDIS.set("user_story:#{self.id}:status", cached_status)
REDIS.expire("user_story:#{self.id}:status", REDIS_EXPIRY)
end
cached_status
end

def inprogress?
if !tasks.blank?
tasks.each do |task|
return true if task.inprogress?
end
return false
else
return false
end
end

def complete?
if !tasks.blank?
tasks.each do |task|
return false unless task.done?
end
return true
else
return false
end
end

# State on backlog
# TODO: Redo for clarity
def state
cached_state = REDIS.get("user_story:#{self.id}:state")
unless cached_state
if self.cannot_be_estimated?
cached_state = 'clarify'
elsif self.acceptance_criteria.blank?
cached_state = 'criteria'
elsif self.story_points.blank?
cached_state = 'estimate'
else
cached_state = 'plan'
end
REDIS.set("user_story:#{self.id}:state", cached_state)
REDIS.expire("user_story:#{self.id}:state", REDIS_EXPIRY)
end
cached_state
end

private

def expire_status
REDIS.del("user_story:#{self.id}:status")
end

def expire_state
REDIS.del("user_story:#{self.id}:state")
end

def expire_story_points
REDIS.del("project:#{self.project.id}:story_points")
end
end

0 comments on commit 963ef7d

Please sign in to comment.