Skip to content

Commit bc1e1b4

Browse files
committed
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.
1 parent 8ec1d84 commit bc1e1b4

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

lib/annotate_rb/model_annotator/model_wrapper.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,10 @@ def max_schema_info_width
113113
end
114114
end
115115

116-
# TODO: Simplify this conditional
117116
def is_column_primary_key?(column_name)
118-
if primary_key
119-
if primary_key.is_a?(Array)
120-
# If the model has multiple primary keys, check if this column is one of them
121-
if primary_key.collect(&:to_sym).include?(column_name.to_sym)
122-
return true
123-
end
124-
elsif column_name.to_sym == primary_key.to_sym
125-
# If model has 1 primary key, check if this column is it
126-
return true
127-
end
128-
end
117+
return false unless primary_key
129118

130-
false
119+
Array(primary_key).map(&:to_sym).include?(column_name.to_sym)
131120
end
132121

133122
def built_attributes

0 commit comments

Comments
 (0)