Refactor `Question.save_condition` by aaronskiba · Pull Request #3501 · DMPRoadmap/roadmap

added 5 commits

April 4, 2025 12:11
This change uses `.map` to refactor/simplify the mapping of `option_list` and `remove_data`. It also removes the needed for temporary arrays.
Refactored `save_condition` method via new `handle_webhook_data` helper method.
  - Helper method returns nil if any of the required webhook_data fields are absent. Else, it constructs and returns the webhook_data hash
  - Returning nil when any fields are absent enables us to simplify the if check that immediately follows (now line 240) to `if c.option_list.empty? || c.webhook_data.nil?`
- Overall, these changes simplify the `save_condition` method and even remove a previous rubocop offense.
- Moved `c.option_list.empty?` immediately after `c.option_list` assignment to streamline logic.
- This change reduces unnecessary processing of `c.remove_data` and `c.webhook_data`.
- Isolating the `c.option_list.empty?` check also simplifies subsequent checks for `c.remove_data.empty?` and c.webhook_data.nil?` later in the code.
- Moved logic for handling option_list and remove_data into separate helper methods (handle_option_list and handle_remove_data).
- This simplifies our `save_condition` method and resolves some previously disabled rubocop offenses.

johnpinto1

@aaronskiba

johnpinto1

@aaronskiba aaronskiba deleted the aaron/refactor-question-save-condition branch

April 7, 2025 20:18