Module: Plutonium::Kanban::Grouping
- Defined in:
- lib/plutonium/kanban/grouping.rb
Overview
Groups an already-authorized, query-applied, UN-paginated relation into ordered, per_column-capped column entries.
Class Method Summary collapse
-
.apply_scope(relation, scope) ⇒ Object
Applies a column scope to a relation.
-
.call(board:, relation:, context:) ⇒ Object
Returns [cards: [records], total: Integer, ...] in column order.
-
.resolve_columns(board, context) ⇒ Object
Resolves the column list from a board.
Class Method Details
.apply_scope(relation, scope) ⇒ Object
Applies a column scope to a relation. Symbol → relation.public_send(sym) (named scope) Proc → relation.instance_exec(&scope) (inline lambda, e.g. -> { where(status: "todo") }) nil → relation unchanged
41 42 43 44 45 46 47 48 |
# File 'lib/plutonium/kanban/grouping.rb', line 41 def apply_scope(relation, scope) case scope when Symbol then relation.public_send(scope) when Proc then relation.instance_exec(&scope) when nil then relation else raise ArgumentError, "Unsupported column scope: #{scope.inspect} (expected Symbol, Proc, or nil)" end end |
.call(board:, relation:, context:) ⇒ Object
Returns [cards: [records], total: Integer, ...] in column order.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/plutonium/kanban/grouping.rb', line 11 def call(board:, relation:, context:) columns = resolve_columns(board, context) pos = board.position_config columns.map do |col| scoped = apply_scope(relation, col.scope) ordered = pos.order(scoped) if board.per_column total = ordered.count cards = ordered.limit(board.per_column).to_a else cards = ordered.to_a total = cards.size end {column: col, cards: cards, total: total} end end |
.resolve_columns(board, context) ⇒ Object
Resolves the column list from a board. For dynamic boards, evaluates the columns_block against the context (which exposes current_user, params, etc. via delegation to view_context). Public so Task 7 (move handler) can call Grouping.resolve_columns(board, context) directly.
32 33 34 35 |
# File 'lib/plutonium/kanban/grouping.rb', line 32 def resolve_columns(board, context) return board.columns unless board.dynamic? Array(context.instance_exec(&board.columns_block)).flatten end |