Module: Studio::Board::Rankable

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/studio/board/rankable.rb

Overview

Shared 100-gap rank read-model for board-orderable records — the kanban columns (McRitchie Studio tasks / news / content) and the depth-chart lanes. A record carries an integer position; the board renders by board_ordered (highest position on top), and a drag-reorder restamps the whole column with 100-gaps via reposition!. Ranking is ZONE-SCOPED: a fresh rank is computed within the record's zone (a kanban stage, a depth-chart position group), so every column ranks independently and 100-spacing leaves room for the next drag insert without a full re-stamp.

This is the read/rank half of the board primitive; the write half is Studio::Board::Reorderable (the controller action that calls reposition!).

class Task < ApplicationRecord
include Studio::Board::Rankable
before_create :set_initial_position   # seeds the genesis rank
end

class DepthChartEntry < ApplicationRecord
include Studio::Board::Rankable
self.board_zone_attr = :position_group   # a lane, not a kanban stage
end

Instance Method Summary collapse

Instance Method Details

#set_initial_positionObject

Seed the genesis rank on create: max(position) within this record's zone plus a 100 gap. A no-op when position is already set, so an explicit rank is never clobbered. Wire from the host via before_create :set_initial_position.



43
44
45
46
47
# File 'app/models/concerns/studio/board/rankable.rb', line 43

def set_initial_position
  return if position.present?

  self.position = self.class.board_next_position(zone_value_for_rank)
end

#zone_value_for_rankObject

This record's zone value (nil when the model ranks globally).



50
51
52
53
# File 'app/models/concerns/studio/board/rankable.rb', line 50

def zone_value_for_rank
  attr = self.class.board_zone_attr
  attr && respond_to?(attr) ? public_send(attr) : nil
end