From bc1e1b4022272150d4d7cd460254ea68feb2023b Mon Sep 17 00:00:00 2001 From: OdenTakashi Date: Thu, 23 Oct 2025 21:26:38 +0900 Subject: [PATCH] refactor: simplify primary key check logic (no functional changes) Unify array and single value handling in is_column_primary_key? using Array() wrapper. Reduces nested conditionals from 15 to 3 lines while maintaining identical behavior. Pure refactoring with zero feature changes. --- lib/annotate_rb/model_annotator/model_wrapper.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/annotate_rb/model_annotator/model_wrapper.rb b/lib/annotate_rb/model_annotator/model_wrapper.rb index 3a8fe146..0a18c836 100644 --- a/lib/annotate_rb/model_annotator/model_wrapper.rb +++ b/lib/annotate_rb/model_annotator/model_wrapper.rb @@ -113,21 +113,10 @@ def max_schema_info_width end end - # TODO: Simplify this conditional def is_column_primary_key?(column_name) - if primary_key - if primary_key.is_a?(Array) - # If the model has multiple primary keys, check if this column is one of them - if primary_key.collect(&:to_sym).include?(column_name.to_sym) - return true - end - elsif column_name.to_sym == primary_key.to_sym - # If model has 1 primary key, check if this column is it - return true - end - end + return false unless primary_key - false + Array(primary_key).map(&:to_sym).include?(column_name.to_sym) end def built_attributes