Class: Eco::API::UseCases::GraphQL::Samples::Pages::Template::Deploy::Applier

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb

Overview

Thin, offline-safe wrapper around a gem Diff::Deploy plan.

The gem's Diff::Deploy is INERT until execute! is called with an explicit executor — this applier keeps that safety and adds a dry-run default: nothing hits the API unless the caller opts in with commit: true AND supplies a live executor. The dry-run path records the batch it WOULD send (so the pre/post-diff and the specs can inspect it) and never calls the executor.

An "executor" is anything responding to execute_workflow_commands(model_or_id, commands:) — in production the gem's graphql.page / Builder::Template update facade. For dry-run + specs a capturing stand-in is enough; see Deploy::RecordingExecutor.

plan = Ecoportal::API::GraphQL::Diff::Deploy.from_versions(before, after, target_doc: prod) applier = Applier.new(plan, target: prod_template) outcome = applier.apply # dry-run: records commands, no API call outcome = applier.apply(commit: true, executor: graphql.page) # live apply

outcome.committed? # => false for dry-run outcome.commands # => the ordered batch that was (or would be) sent outcome.unsupported # => [Change, ...] the plan could not synthesise (needs a human)

Defined Under Namespace

Classes: Outcome, TargetBoundExecutor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plan, target: nil) ⇒ Applier

Returns a new instance of Applier.

Parameters:

  • plan (Ecoportal::API::GraphQL::Diff::Deploy)

    the gem deploy plan.

  • target (#id, nil) (defaults to: nil)

    the template/page model the batch applies to (needed for a live executor that reads id/patchVer). Optional for dry-run.



53
54
55
56
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 53

def initialize(plan, target: nil)
  @plan   = plan
  @target = target
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.



48
49
50
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 48

def plan
  @plan
end

#targetObject (readonly)

Returns the value of attribute target.



48
49
50
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 48

def target
  @target
end

Instance Method Details

#apply(commit: false, executor: nil, allow_partial: false) ⇒ Outcome

Apply the plan's command batch.

Parameters:

  • commit (Boolean) (defaults to: false)

    false (default) = dry-run, records the batch and returns without touching the API. true = live apply (requires an executor).

  • executor (#execute_workflow_commands, nil) (defaults to: nil)

    the live mutation facade. Ignored on dry-run.

  • allow_partial (Boolean) (defaults to: false)

    forwarded to the gem plan: apply even with unsupported changes.

Returns:



65
66
67
68
69
70
71
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 65

def apply(commit: false, executor: nil, allow_partial: false)
  return blocked_outcome unless deployable?(allow_partial)

  return dry_run_outcome unless commit

  commit_outcome(executor, allow_partial: allow_partial)
end

#commandsObject

The ordered command batch (delegates to the gem plan).



74
75
76
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 74

def commands
  plan.commands
end

#fully_supported?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 83

def fully_supported?
  plan.fully_supported?
end

#unsupportedObject

Changes the gem plan could not synthesise — surfaced so a human gates the deploy.



79
80
81
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/applier.rb', line 79

def unsupported
  plan.unsupported
end