Class: Ecoportal::API::GraphQL::Builder::TemplateBuilder
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Builder::TemplateBuilder
- Defined in:
- lib/ecoportal/api/graphql/builder/template_builder.rb
Overview
Build-from-scratch emitter for a template/workflow: turns a DECLARATIVE spec
(stages -> sections -> fields -> options / config / gauge-stops) into an ordered batch of
built WorkflowCommand hashes, ready for Builder::Template#create(commands:) /
#update(model, commands:) (which wrap executeWorkflowCommands).
This is the gem-level, reusable BUILD emitter (previously a one-off in eco-helpers samples).
It shares ONE emission layer with the DIFF-DEPLOY pipeline: both produce an ordered
WorkflowCommand batch, and both use the SAME placeholderId id-threading primitive that
Diff::CommandSynthesizer uses — a newly-created node is addressed by a client-chosen
placeholderId, and every later command in the same batch that references it substitutes
that placeholder (the server has not assigned real ids yet). Here every node is brand new,
so the whole batch is threaded through placeholders.
SPEC SHAPE (all keys optional unless noted; only VALID command inputs are emitted):
{ stages: [ { name: 'Report', ordering: 0, sections: [ # addStage(name, ordering) { layout: 'ONE_COLUMN', fields: [ # addSection(layout) + addStageSection { field_type: 'PlainText', label: 'Description', column: 0, description: 'ID:token' }, # addField (+ editFieldConfiguration for description) { field_type: 'Select', label: 'Severity', options: [ { label: 'Low', weight: 0 }, ... ], # addSelectFieldOption config: { select: { multiple: false } } }, # editFieldConfiguration(byType:) { field_type: 'Gauge', label: 'Risk', stops: [ { threshold: 0, color: '#0f0' }, ... ], # addGaugeFieldStop config: { gauge: { max: 100.0 } } } ] } ] } ] }
ORDER — addStage -> addSection -> addStageSection -> addField -> (addSelectFieldOption | addGaugeFieldStop | editFieldConfiguration). This is the dependency-safe order the workflow command bus expects; placeholderId resolution makes the intra-batch references valid.
SAFETY — only keys present in each command input's VALID_KEYS are emitted (the input classes
slice + compact). A spec key with no corresponding command input is dropped, not fabricated.
field_type shape and per-type config (byType) are NOT invented: config is passed through
under its byType sub-hash exactly as given (the caller supplies confirmed byType keys), and
is emitted only for a field that carries one.
Instance Method Summary collapse
-
#commands ⇒ Object
(also: #to_commands)
Ordered Array of built command hashes ({ commandKey => input }), placeholder-threaded.
-
#initialize(spec) ⇒ TemplateBuilder
constructor
A new instance of TemplateBuilder.
- #to_h ⇒ Object
Constructor Details
#initialize(spec) ⇒ TemplateBuilder
Returns a new instance of TemplateBuilder.
48 49 50 51 52 53 |
# File 'lib/ecoportal/api/graphql/builder/template_builder.rb', line 48 def initialize(spec) @spec = symbolize(spec || {}) @commands = [] @counter = 0 @built = false end |
Instance Method Details
#commands ⇒ Object Also known as: to_commands
Ordered Array of built command hashes ({ commandKey => input }), placeholder-threaded.
56 57 58 59 60 61 |
# File 'lib/ecoportal/api/graphql/builder/template_builder.rb', line 56 def commands return @commands if @built @built = true build_all end |
#to_h ⇒ Object
66 67 68 |
# File 'lib/ecoportal/api/graphql/builder/template_builder.rb', line 66 def to_h { commands: commands } end |