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
22
|
# File 'lib/jirametrics/cycletime_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/cycletime_config.rb', line 9
def file_system
@file_system
end
|
#label ⇒ Object
Returns the value of attribute label.
9
10
11
|
# File 'lib/jirametrics/cycletime_config.rb', line 9
def label
@label
end
|
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
9
10
11
|
# File 'lib/jirametrics/cycletime_config.rb', line 9
def possible_statuses
@possible_statuses
end
|
#settings ⇒ Object
Returns the value of attribute settings.
9
10
11
|
# File 'lib/jirametrics/cycletime_config.rb', line 9
def settings
@settings
end
|
Instance Method Details
#age(issue, today: nil) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/jirametrics/cycletime_config.rb', line 121
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
114
115
116
117
118
119
|
# File 'lib/jirametrics/cycletime_config.rb', line 114
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
39
40
41
|
# File 'lib/jirametrics/cycletime_config.rb', line 39
def done? issue
started_stopped_times(issue).last
end
|
#fabricate_change_item(time) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/jirametrics/cycletime_config.rb', line 53
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
105
106
107
|
# File 'lib/jirametrics/cycletime_config.rb', line 105
def flush_cache
@cache = nil
end
|
#in_progress?(issue) ⇒ Boolean
34
35
36
37
|
# File 'lib/jirametrics/cycletime_config.rb', line 34
def in_progress? issue
started_time, stopped_time = started_stopped_times(issue)
started_time && stopped_time.nil?
end
|
#start_at(block = nil) ⇒ Object
24
25
26
27
|
# File 'lib/jirametrics/cycletime_config.rb', line 24
def start_at block = nil
@start_at = block unless block.nil?
@start_at
end
|
#started_stopped_changes(issue) ⇒ Object
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
98
|
# File 'lib/jirametrics/cycletime_config.rb', line 67
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
109
110
111
112
|
# File 'lib/jirametrics/cycletime_config.rb', line 109
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
100
101
102
103
|
# File 'lib/jirametrics/cycletime_config.rb', line 100
def started_stopped_times issue
started, stopped = started_stopped_changes(issue)
[started&.time, stopped&.time]
end
|
#started_time(issue) ⇒ Object
43
44
45
46
|
# File 'lib/jirametrics/cycletime_config.rb', line 43
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
29
30
31
32
|
# File 'lib/jirametrics/cycletime_config.rb', line 29
def stop_at block = nil
@stop_at = block unless block.nil?
@stop_at
end
|
#stopped_time(issue) ⇒ Object
48
49
50
51
|
# File 'lib/jirametrics/cycletime_config.rb', line 48
def stopped_time issue
@file_system.deprecated date: '2024-10-16', message: 'Use started_stopped_times() instead'
started_stopped_times(issue).last
end
|