Module: Ecoportal::API::GraphQL::Model::Template::CommandGrouper

Defined in:
lib/ecoportal/api/graphql/model/template/command_grouper.rb

Overview

Groups an ordered command batch into chunks no larger than chunk_size, never splitting a placeholder-minting command away from any OTHER command in the SAME batch that references that placeholder (a placeholderId is only valid within the ONE executeWorkflowCommands/updatePageTemplate call that mints it — 18_template_editor_save_path.md section B.1). Connected components (union-find over "which commands share a placeholder token") are packed into chunks in first-appearance order, so a chunk boundary only ever falls BETWEEN independent groups, never inside one.

Constant Summary collapse

PLACEHOLDER_RE =
/\Aph_/

Class Method Summary collapse

Class Method Details

.chunk(commands, chunk_size) ⇒ Array<Array<Hash>>

Returns ordered chunks.

Parameters:

  • commands (Array<Hash>) —

    built command hashes ({ commandKey => input }).

  • chunk_size (Integer)

Returns:

  • (Array<Array<Hash>>) —

    ordered chunks.



21
22
23
# File 'lib/ecoportal/api/graphql/model/template/command_grouper.rb', line 21

def chunk(commands, chunk_size)
  slice_groups(group(commands), chunk_size)
end

.tokens_in(commands) ⇒ Object

Every ph_... token referenced ANYWHERE in commands (minted or referenced). Public: StagedExecutor's stale-placeholder guard uses this directly.



27
28
29
# File 'lib/ecoportal/api/graphql/model/template/command_grouper.rb', line 27

def tokens_in(commands)
  commands.flat_map { |c| placeholder_tokens(c) }.uniq
end