Module: TimeTrackable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Gitlab::Utils::StrongMemoize
- Included in:
- Issue, MergeRequest
- Defined in:
- app/models/concerns/time_trackable.rb
Overview
TimeTrackable concern
Contains functionality related to objects that support time tracking.
Used by Issue and MergeRequest.
Instance Method Summary collapse
- #clear_memoized_total_time_spent ⇒ Object
- #human_time_change ⇒ Object
- #human_time_estimate ⇒ Object
- #human_total_time_spent ⇒ Object
- #reload(*args) ⇒ Object
- #reset ⇒ Object
- #set_time_estimate_default_value ⇒ Object
-
#spend_time(options) ⇒ Object
(also: #spend_time=)
rubocop:disable Gitlab/ModuleWithInstanceVariables.
- #time_change ⇒ Object
- #time_estimate ⇒ Object
- #time_estimate=(val) ⇒ Object
-
#total_time_spent ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables.
Instance Method Details
#clear_memoized_total_time_spent ⇒ Object
28 29 30 |
# File 'app/models/concerns/time_trackable.rb', line 28 def clear_memoized_total_time_spent clear_memoization(:total_time_spent) end |
#human_time_change ⇒ Object
84 85 86 |
# File 'app/models/concerns/time_trackable.rb', line 84 def human_time_change Gitlab::TimeTrackingFormatter.output(time_change) end |
#human_time_estimate ⇒ Object
88 89 90 |
# File 'app/models/concerns/time_trackable.rb', line 88 def human_time_estimate Gitlab::TimeTrackingFormatter.output(time_estimate) end |
#human_total_time_spent ⇒ Object
76 77 78 |
# File 'app/models/concerns/time_trackable.rb', line 76 def human_total_time_spent Gitlab::TimeTrackingFormatter.output(total_time_spent) end |
#reload(*args) ⇒ Object
38 39 40 41 42 |
# File 'app/models/concerns/time_trackable.rb', line 38 def reload(*args) clear_memoized_total_time_spent super(*args) end |
#reset ⇒ Object
32 33 34 35 36 |
# File 'app/models/concerns/time_trackable.rb', line 32 def reset clear_memoized_total_time_spent super end |
#set_time_estimate_default_value ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'app/models/concerns/time_trackable.rb', line 100 def set_time_estimate_default_value return if new_record? return unless has_attribute?(:time_estimate) # time estimate can be set to nil, in case of an invalid value, e.g. a String instead of a number, in which case # we should not be overwriting it to default value, but rather have the validation catch the error return if time_estimate_changed? self.time_estimate = self.class.column_defaults['time_estimate'] if read_attribute(:time_estimate).nil? end |
#spend_time(options) ⇒ Object Also known as: spend_time=
rubocop:disable Gitlab/ModuleWithInstanceVariables
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/time_trackable.rb', line 45 def spend_time() @time_spent = [:duration] @time_spent_note_id = [:note_id] @time_spent_user = User.find([:user_id]) @spent_at = [:spent_at] @summary = [:summary] @original_total_time_spent = nil @category_id = category_id([:category]) return if @time_spent == 0 @timelog = if @time_spent == :reset reset_spent_time else add_or_subtract_spent_time end end |
#time_change ⇒ Object
80 81 82 |
# File 'app/models/concerns/time_trackable.rb', line 80 def time_change @timelog&.time_spent.to_i # rubocop:disable Gitlab/ModuleWithInstanceVariables end |
#time_estimate ⇒ Object
96 97 98 |
# File 'app/models/concerns/time_trackable.rb', line 96 def time_estimate super || self.class.column_defaults['time_estimate'] end |
#time_estimate=(val) ⇒ Object
92 93 94 |
# File 'app/models/concerns/time_trackable.rb', line 92 def time_estimate=(val) val.is_a?(Integer) ? super([val, Gitlab::Database::MAX_INT_VALUE].min) : super(val) end |
#total_time_spent ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables
65 66 67 68 69 70 71 72 73 |
# File 'app/models/concerns/time_trackable.rb', line 65 def total_time_spent sum = timelogs.sum(:time_spent) # A new restriction has been introduced to limit total time spent to - # Timelog::MAX_TOTAL_TIME_SPENT or 3.154e+7 seconds (approximately a year, a generous limit) # Since there could be existing records that breach the limit, check and return the maximum/minimum allowed value. # (some issuable might have total time spent that's negative because a validation was missing.) sum.clamp(-Timelog::MAX_TOTAL_TIME_SPENT, Timelog::MAX_TOTAL_TIME_SPENT) end |