Class: Jira::Auto::Tool::Performer::SprintEndDateUpdater

Inherits:
PrefixSprintUpdater show all
Defined in:
lib/jira/auto/tool/performer/sprint_end_date_updater.rb

Instance Attribute Summary collapse

Attributes inherited from PrefixSprintUpdater

#tool

Instance Method Summary collapse

Methods inherited from PrefixSprintUpdater

#first_sprint_to_act_on?, #run, #sprint_prefixes

Constructor Details

#initialize(tool, from_string, new_end_date) ⇒ SprintEndDateUpdater

Returns a new instance of SprintEndDateUpdater.



12
13
14
15
16
17
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 12

def initialize(tool, from_string, new_end_date)
  super(tool)

  @from_string_regex = Regexp.new(Regexp.escape(from_string))
  @new_end_date = Time.parse(new_end_date)
end

Instance Attribute Details

#from_string_regexObject (readonly)

Returns the value of attribute from_string_regex.



10
11
12
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 10

def from_string_regex
  @from_string_regex
end

#new_end_dateObject (readonly)

Returns the value of attribute new_end_date.



10
11
12
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 10

def new_end_date
  @new_end_date
end

Instance Method Details

#act_on_sprints_for_sprint_prefix(sprint_prefix) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 19

def act_on_sprints_for_sprint_prefix(sprint_prefix)
  prefix_sprints = sprint_prefix.sprints
  update_action = :do_nothing
  new_start_date = nil

  prefix_sprints.each do |sprint|
    if first_sprint_to_act_on?(sprint.name)
      update_sprint_end_date(sprint)
      update_action = :shift_sprint_to_new_start_date
    else
      send(update_action, sprint, new_start_date)
    end

    new_start_date = sprint.end_date
  end
end

#do_nothing(_sprint, _new_start_date) ⇒ Object



36
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 36

def do_nothing(_sprint, _new_start_date) end

#shift_sprint_to_new_start_date(sprint, new_start_date) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 43

def shift_sprint_to_new_start_date(sprint, new_start_date)
  length_in_days = sprint.length_in_days

  sprint.start_date = new_start_date
  sprint.end_date = new_start_date + length_in_days.days

  sprint.save
end

#update_sprint_end_date(sprint) ⇒ Object



38
39
40
41
# File 'lib/jira/auto/tool/performer/sprint_end_date_updater.rb', line 38

def update_sprint_end_date(sprint)
  sprint.end_date = new_end_date
  sprint.save
end