Skip to content

Commit

Permalink
Fix regex match group handling after moving to case statements
Browse files Browse the repository at this point in the history
The rubocop autocorrect for Style/CaseLikeIf does not take into
account the match operator for regex, which in this case
returns the matched data when using it with and if/elsif statement.
After just moving this to an case statement, the data is not returned
anymore.
This could be fixed by using the `$LAST_MATCH_INFO` pseudo variable which
contains the whole `MatchData` object of the latest regex matching group.
  • Loading branch information
krauselukas committed Jul 17, 2020
1 parent 1de2cc9 commit 6909ea7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/repositories_controller.rb
Expand Up @@ -197,9 +197,9 @@ def follow_change_flag_command(flag_type)
case params[:command]
when 'remove'
@main_object.flags.of_type(flag_type).where(repo: params[:repository], architecture: architecture).delete_all
when %r{^set-(?<status>disable|enable)$}
when /^set-(?<status>disable|enable)$/
flag = @main_object.flags.find_or_create_by(flag: flag_type, repo: params[:repository], architecture: architecture)
flag.update(status: status)
flag.update(status: $LAST_MATCH_INFO['status'])
end
@main_object.store
end
Expand Down

0 comments on commit 6909ea7

Please sign in to comment.