Skip to content

Commit

Permalink
guarding alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdavidhamilton committed Dec 1, 2023
1 parent 01f8d17 commit 379ebe6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/services/visit_changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ class VisitChanges

# @return [Boolean]
def new_modules?
# for consistency change me too
previous_visit && new_modules.any?
end

# @param mod [Training::Module]
# @return [Boolean]
def new_module?(mod)
return false if user.course.started?(mod)
# chained conditions
previous_visit &&
previous_visit.started_at.to_i < mod.first_published_at.to_i &&
!user.course.started?(mod)

previous_visit && previous_visit.started_at.to_i < mod.first_published_at.to_i
# or
# primary condition with two guards
return false if previous_visit.nil? || user.course.started?(mod)

previous_visit.started_at < mod.first_published_at
end

# @return [Array<Training::Module>]
Expand Down

0 comments on commit 379ebe6

Please sign in to comment.