Skip to content

Commit

Permalink
Minor tweak to appease Hakiri
Browse files Browse the repository at this point in the history
  • Loading branch information
irisfaraway committed Jan 16, 2018
1 parent 2dbfc86 commit abaa75a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/concerns/can_generate_reg_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ def generate_reg_identifier
def latest_counter
# Get the counter for reg_identifiers, or create it if it doesn't exist
counter = Counter.where(_id: "regid").first || Counter.create(_id: "regid", seq: 1)
counter_number = counter.seq

# Increment the counter until no reg_identifier is using it
while Registration.where(reg_identifier: /CBD[U|L]#{counter.seq}/).exists?
# We reset counter_number instead of using counter.seq as Hakiri warns against model values in regexes
while Registration.where(reg_identifier: /CBD[U|L]#{counter_number}/).exists?
counter.increment
counter_number = counter.seq
end

counter.seq
counter_number
end
end

0 comments on commit abaa75a

Please sign in to comment.