Class: CycleTimeConfig

Inherits:
Object
  • Object
show all
Includes:
SelfOrIssueDispatcher
Defined in:
lib/jirametrics/cycletime_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SelfOrIssueDispatcher

#method_missing, #respond_to_missing?

Constructor Details

#initialize(parent_config:, label:, block:, file_system: nil, today: Date.today) ⇒ CycleTimeConfig

Returns a new instance of CycleTimeConfig.



11
12
13
14
15
16
17
18
19
20
# File 'lib/jirametrics/cycletime_config.rb', line 11

def initialize parent_config:, label:, block:, file_system: nil, today: Date.today
  @parent_config = parent_config
  @label = label
  @today = today

  # If we hit something deprecated and this is nil then we'll blow up. Although it's ugly, this
  # may make it easier to find problems in the test code ;-)
  @file_system = file_system
  instance_eval(&block) unless block.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SelfOrIssueDispatcher

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



9
10
11
# File 'lib/jirametrics/cycletime_config.rb', line 9

def label
  @label
end

#parent_configObject (readonly)

Returns the value of attribute parent_config.



9
10
11
# File 'lib/jirametrics/cycletime_config.rb', line 9

def parent_config
  @parent_config
end

Instance Method Details

#age(issue, today: nil) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/jirametrics/cycletime_config.rb', line 103

def age issue, today: nil
  start = started_stopped_times(issue).first
  stop = today || @today || Date.today
  return nil if start.nil? || stop.nil?

  (stop.to_date - start.to_date).to_i + 1
end

#cycletime(issue) ⇒ Object



96
97
98
99
100
101
# File 'lib/jirametrics/cycletime_config.rb', line 96

def cycletime issue
  start, stop = started_stopped_times(issue)
  return nil if start.nil? || stop.nil?

  (stop.to_date - start.to_date).to_i + 1
end

#done?(issue) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/jirametrics/cycletime_config.rb', line 37

def done? issue
  started_stopped_times(issue).last
end

#fabricate_change_item(time) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jirametrics/cycletime_config.rb', line 51

def fabricate_change_item time
  @file_system.deprecated(
    date: '2024-12-16', message: "This method should now return a ChangeItem not a #{time.class}", depth: 4
  )
  raw = {
    'field' => 'Fabricated change',
    'to' => '0',
    'toString' => '',
    'from' => '0',
    'fromString' => ''
  }
  ChangeItem.new raw: raw, time: time, artificial: true, author_raw: nil
end

#in_progress?(issue) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/jirametrics/cycletime_config.rb', line 32

def in_progress? issue
  started_time, stopped_time = started_stopped_times(issue)
  started_time && stopped_time.nil?
end

#possible_statusesObject



111
112
113
114
115
116
117
118
119
# File 'lib/jirametrics/cycletime_config.rb', line 111

def possible_statuses
  if parent_config.is_a? BoardConfig
    project_config = parent_config.project_config
  else
    # TODO: This will go away when cycletimes are no longer supported inside html_reports
    project_config = parent_config.file_config.project_config
  end
  project_config.possible_statuses
end

#start_at(block = nil) ⇒ Object



22
23
24
25
# File 'lib/jirametrics/cycletime_config.rb', line 22

def start_at block = nil
  @start_at = block unless block.nil?
  @start_at
end

#started_stopped_changes(issue) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jirametrics/cycletime_config.rb', line 65

def started_stopped_changes issue
  started = @start_at.call(issue)
  stopped = @stop_at.call(issue)

  # Obscure edge case where some of the start_at and stop_at blocks might return false in place of nil.
  # If they are false then explicitly make them nil.
  started ||= nil
  stopped ||= nil

  # These are only here for backwards compatibility. Hopefully nobody will ever need them.
  started = fabricate_change_item(started) if !started.nil? && !started.is_a?(ChangeItem)
  stopped = fabricate_change_item(stopped) if !stopped.nil? && !stopped.is_a?(ChangeItem)

  # In the case where started and stopped are exactly the same time, we pretend that
  # it just stopped and never started. This allows us to have logic like 'in or right of'
  # for the start and not have it conflict.
  started = nil if started&.time == stopped&.time

  [started, stopped]
end

#started_stopped_dates(issue) ⇒ Object



91
92
93
94
# File 'lib/jirametrics/cycletime_config.rb', line 91

def started_stopped_dates issue
  started_time, stopped_time = started_stopped_times(issue)
  [started_time&.to_date, stopped_time&.to_date]
end

#started_stopped_times(issue) ⇒ Object



86
87
88
89
# File 'lib/jirametrics/cycletime_config.rb', line 86

def started_stopped_times issue
  started, stopped = started_stopped_changes(issue)
  [started&.time, stopped&.time]
end

#started_time(issue) ⇒ Object



41
42
43
44
# File 'lib/jirametrics/cycletime_config.rb', line 41

def started_time issue
  @file_system.deprecated date: '2024-10-16', message: 'Use started_stopped_times() instead'
  started_stopped_times(issue).first
end

#stop_at(block = nil) ⇒ Object



27
28
29
30
# File 'lib/jirametrics/cycletime_config.rb', line 27

def stop_at block = nil
  @stop_at = block unless block.nil?
  @stop_at
end

#stopped_time(issue) ⇒ Object



46
47
48
49
# File 'lib/jirametrics/cycletime_config.rb', line 46

def stopped_time issue
  @file_system.deprecated date: '2024-10-16', message: 'Use started_stopped_times() instead'
  started_stopped_times(issue).last
end