Skip to content

Commit

Permalink
Refactor unless to if, update early return
Browse files Browse the repository at this point in the history
  • Loading branch information
CuddlyBunion341 committed Jun 26, 2024
1 parent 086cb54 commit 29c148e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/models/finished_timer_session_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def validate_minimal_duration
end

def validate_day_limit
return unless (
return if (
@record.splittable_hours + TimerSession.created_by(@record.user)
.recorded_on(@record.timer_start.to_date).sum(:hours)
) > SettingsManager.max_hours_recorded_per_day.to_f
) <= SettingsManager.max_hours_recorded_per_day.to_f

@record.errors.add(:timer_start, :limit_reached_day)
end

def validate_session_limit
return unless @record.splittable_hours > SettingsManager.max_hours_recorded_per_session.to_f
return if @record.splittable_hours <= SettingsManager.max_hours_recorded_per_session.to_f

@record.errors.add(:timer_start, :limit_reached_session)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/unfinished_timer_session_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def validate(record)
end

def validate_start_before_end_date
return if @record.timer_start.blank? || @record.timer_end.blank?
return if @record.timer_end.blank?
return if @record.timer_end > @record.timer_start

@record.errors.add(:timer_start, :after_end)
Expand Down

0 comments on commit 29c148e

Please sign in to comment.