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     # a lane (QB/RB/…), not a kanban stage
self.board_rank_attr = :depth        # rank by depth; `position` is a string
self.board_rank_order = :asc         # depth 1 (the starter) sits on top
end

Instance Method Summary collapse

Instance Method Details

#set_initial_positionObject

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



62
63
64
65
66
67
# File 'app/models/concerns/studio/board/rankable.rb', line 62

def set_initial_position
  rank_attr = self.class.board_rank_attr
  return if public_send(rank_attr).present?

  public_send("#{rank_attr}=", 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).



70
71
72
73
# File 'app/models/concerns/studio/board/rankable.rb', line 70

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