Class: CycleTimeConfig
Instance Attribute Summary collapse
Instance Method Summary
collapse
#method_missing, #respond_to_missing?
Constructor Details
#initialize(possible_statuses:, label:, block:, settings:, file_system: nil, today: Date.today) ⇒ CycleTimeConfig
Returns a new instance of CycleTimeConfig.
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/jirametrics/cycle_time_config.rb', line 11
def initialize possible_statuses:, label:, block:, settings:, file_system: nil, today: Date.today
@possible_statuses = possible_statuses
@label = label
@today = today
@settings = settings
@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
#file_system ⇒ Object
Returns the value of attribute file_system.
9
10
11
|
# File 'lib/jirametrics/cycle_time_config.rb', line 9
def file_system
@file_system
end
|
#label ⇒ Object
Returns the value of attribute label.
9
10
11
|
# File 'lib/jirametrics/cycle_time_config.rb', line 9
def label
@label
end
|
#settings ⇒ Object
Returns the value of attribute settings.
9
10
11
|
# File 'lib/jirametrics/cycle_time_config.rb', line 9
def settings
@settings
end
|
Instance Method Details
#age(issue, today: nil) ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/jirametrics/cycle_time_config.rb', line 120
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
113
114
115
116
117
118
|
# File 'lib/jirametrics/cycle_time_config.rb', line 113
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
38
39
40
|
# File 'lib/jirametrics/cycle_time_config.rb', line 38
def done? issue
started_stopped_times(issue).last
end
|
#fabricate_change_item(time) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/jirametrics/cycle_time_config.rb', line 52
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
|
#flush_cache ⇒ Object
104
105
106
|
# File 'lib/jirametrics/cycle_time_config.rb', line 104
def flush_cache
@cache = nil
end
|
#in_progress?(issue) ⇒ Boolean
33
34
35
36
|
# File 'lib/jirametrics/cycle_time_config.rb', line 33
def in_progress? issue
started_time, stopped_time = started_stopped_times(issue)
started_time && stopped_time.nil?
end
|
#possible_statuses ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/jirametrics/cycle_time_config.rb', line 128
def possible_statuses
if parent_config.is_a? BoardConfig
project_config = parent_config.project_config
else
project_config = parent_config.file_config.project_config
end
project_config.possible_statuses
end
|
#start_at(block = nil) ⇒ Object
23
24
25
26
|
# File 'lib/jirametrics/cycle_time_config.rb', line 23
def start_at block = nil
@start_at = block unless block.nil?
@start_at
end
|
#started_stopped_changes(issue) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/jirametrics/cycle_time_config.rb', line 66
def started_stopped_changes issue
cache_key = "#{issue.key}:#{issue.board.id}"
last_result = (@cache ||= {})[cache_key]
return *last_result if last_result && settings['cache_cycletime_calculations']
started = @start_at.call(issue)
stopped = @stop_at.call(issue)
started ||= nil
stopped ||= nil
started = fabricate_change_item(started) if !started.nil? && !started.is_a?(ChangeItem)
stopped = fabricate_change_item(stopped) if !stopped.nil? && !stopped.is_a?(ChangeItem)
started = nil if started&.time == stopped&.time
result = [started, stopped]
if last_result && result != last_result
@file_system.error(
"Calculation mismatch; this could break caching. #{issue.inspect} new=#{result.inspect}, " \
"previous=#{last_result.inspect}"
)
end
@cache[cache_key] = result
result
end
|
#started_stopped_dates(issue) ⇒ Object
108
109
110
111
|
# File 'lib/jirametrics/cycle_time_config.rb', line 108
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
99
100
101
102
|
# File 'lib/jirametrics/cycle_time_config.rb', line 99
def started_stopped_times issue
started, stopped = started_stopped_changes(issue)
[started&.time, stopped&.time]
end
|
#started_time(issue) ⇒ Object
42
43
44
45
|
# File 'lib/jirametrics/cycle_time_config.rb', line 42
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
28
29
30
31
|
# File 'lib/jirametrics/cycle_time_config.rb', line 28
def stop_at block = nil
@stop_at = block unless block.nil?
@stop_at
end
|
#stopped_time(issue) ⇒ Object
47
48
49
50
|
# File 'lib/jirametrics/cycle_time_config.rb', line 47
def stopped_time issue
@file_system.deprecated date: '2024-10-16', message: 'Use started_stopped_times() instead'
started_stopped_times(issue).last
end
|