Module: TimeTrackable
- Extended by:
- ActiveSupport::Concern
- 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
- #human_time_change ⇒ Object
- #human_time_estimate ⇒ Object
- #human_total_time_spent ⇒ Object
- #set_time_estimate_default_value ⇒ Object
-
#spend_time(options) ⇒ Object
(also: #spend_time=)
rubocop:disable Gitlab/ModuleWithInstanceVariables.
- #time_change ⇒ Object
- #time_estimate=(val) ⇒ Object
-
#total_time_spent ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables.
Instance Method Details
#human_time_change ⇒ Object
59 60 61 |
# File 'app/models/concerns/time_trackable.rb', line 59 def human_time_change Gitlab::TimeTrackingFormatter.output(time_change) end |
#human_time_estimate ⇒ Object
63 64 65 |
# File 'app/models/concerns/time_trackable.rb', line 63 def human_time_estimate Gitlab::TimeTrackingFormatter.output(time_estimate) end |
#human_total_time_spent ⇒ Object
51 52 53 |
# File 'app/models/concerns/time_trackable.rb', line 51 def human_total_time_spent Gitlab::TimeTrackingFormatter.output(total_time_spent) end |
#set_time_estimate_default_value ⇒ Object
71 72 73 74 75 76 |
# File 'app/models/concerns/time_trackable.rb', line 71 def set_time_estimate_default_value return if new_record? return unless has_attribute?(:time_estimate) self.time_estimate ||= self.class.column_defaults['time_estimate'] end |
#spend_time(options) ⇒ Object Also known as: spend_time=
rubocop:disable Gitlab/ModuleWithInstanceVariables
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/concerns/time_trackable.rb', line 28 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 return if @time_spent == 0 @timelog = if @time_spent == :reset reset_spent_time else add_or_subtract_spent_time end end |
#time_change ⇒ Object
55 56 57 |
# File 'app/models/concerns/time_trackable.rb', line 55 def time_change @timelog&.time_spent.to_i # rubocop:disable Gitlab/ModuleWithInstanceVariables end |
#time_estimate=(val) ⇒ Object
67 68 69 |
# File 'app/models/concerns/time_trackable.rb', line 67 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
47 48 49 |
# File 'app/models/concerns/time_trackable.rb', line 47 def total_time_spent timelogs.sum(:time_spent) end |