rename from sibling_columns to surroundings

This commit is contained in:
Tomas Costantino
2025-12-09 11:07:22 +01:00
parent 820e8ef5e4
commit 5d1ce5a656
2 changed files with 7 additions and 6 deletions
+1 -6
View File
@@ -6,10 +6,5 @@ class Column < ApplicationRecord
has_many :cards, dependent: :nullify
after_save_commit -> { cards.touch_all }, if: -> { saved_change_to_name? || saved_change_to_color? }
after_create_commit -> { sibling_columns.touch_all }
after_destroy_commit -> { board.cards.touch_all; sibling_columns.touch_all }
def sibling_columns
board.columns.where.not(id:).sorted
end
after_destroy_commit -> { board.cards.touch_all }
end
+6
View File
@@ -5,6 +5,8 @@ module Column::Positioned
scope :sorted, -> { order(position: :asc) }
before_create :set_position
after_create_commit -> { surroundings.touch_all }
after_destroy_commit -> { surroundings.touch_all }
end
def move_left
@@ -31,6 +33,10 @@ module Column::Positioned
right_column.nil?
end
def surroundings
board.columns.where(id: [ left_column&.id, right_column&.id ].compact)
end
private
def set_position
max_position = board.columns.maximum(:position) || 0