Class: Eco::API::UseCases::GraphQL::Samples::Pages::Template::Base

Inherits:
Base show all
Defined in:
lib/eco/api/usecases/graphql/samples/pages/template/base.rb

Overview

Build-from-scratch template (workflow) construction use case.

A subclass declares the desired template structure in #declare(emitter) using the CommandEmitter DSL; the base turns it into an ordered command batch and applies it via graphql.template.create / update (executeWorkflowCommands). simulate? previews the batch without writing. The emitted batch (#desired_commands) is unit-testable with no live client.

class Custom::UseCase::BuildIncidentTemplate < Samples::Pages::Template::Base name 'build-incident-template'

def declare(t)
  t.stage(name: 'Report', ordering: 0) do |stage|
    stage.section(layout: 'content') do |section|
      section.field(label: 'Description', field_type: 'plain_text')
    end
  end
end

end

Instance Attribute Summary

Attributes included from Lib::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods inherited from Base

#main

Methods included from Language::Methods::CallDetector

#called_via?

Methods included from Language::AuxiliarLogger

#log

Methods inherited from Common::Loaders::UseCase

#cli_apply!, #initialize, #main

Methods included from Common::Loaders::UseCase::CliIdentify

#cli, #cli!

Methods included from Common::Loaders::UseCase::TargetModel

#target_model

Methods included from Common::Loaders::UseCase::Type

#type

Methods inherited from Common::Loaders::CaseBase

#name, name_only_once!, original_name

Constructor Details

This class inherits a constructor from Eco::API::Common::Loaders::UseCase

Instance Method Details

#declare(_emitter) ⇒ Object

Declare the desired template structure onto the given CommandEmitter.

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/eco/api/usecases/graphql/samples/pages/template/base.rb', line 38

def declare(_emitter)
  raise NotImplementedError, "Implement #declare(emitter) in #{self.class}"
end

#desired_commandsObject

The ordered command batch this template would apply. Pure — no client needed.



43
44
45
46
47
# File 'lib/eco/api/usecases/graphql/samples/pages/template/base.rb', line 43

def desired_commands
  emitter = CommandEmitter.new
  declare(emitter)
  emitter.commands
end

#processObject



26
27
28
29
30
31
32
33
# File 'lib/eco/api/usecases/graphql/samples/pages/template/base.rb', line 26

def process
  commands = desired_commands
  if simulate?
    log(:info) { preview_message(commands) }
    return nil
  end
  apply(commands)
end