Class: Browserctl::State::Mutator

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/state/mutator.rb

Overview

Drives the “rotate this bundle’s bound flow and re-save” operation without dragging in CLI input concerns. Extracted from ‘Browserctl::Commands::State.run_rotate` so the rotation flow is:

- testable without spawning a CLI subprocess
- reusable from Workflow if a workflow ever needs to drive rotation
  programmatically.

Errors are surfaced by raising typed ‘Browserctl::FlowError` so the caller (CLI or Workflow) can decide how to render them. The CLI maps to a non-zero exit; a Workflow caller may catch and continue.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(client:, registry: Browserctl::FlowRegistry) ⇒ Mutator

Returns a new instance of Mutator.



25
26
27
28
# File 'lib/browserctl/state/mutator.rb', line 25

def initialize(client:, registry: Browserctl::FlowRegistry)
  @client   = client
  @registry = registry
end

Instance Method Details

#rotate(name:, params: {}, page: nil) ⇒ Result

Re-runs the flow bound to the bundle <name> and re-saves it under the same origins. ‘params` is the merged param set (file + caller-provided); the CLI does the file/k=v parsing before handing values in.

Returns:

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/browserctl/state/mutator.rb', line 36

def rotate(name:, params: {}, page: nil)
  manifest = read_manifest!(name)
  flow     = resolve_bound_flow!(manifest)

  flow.run(page: page, client: @client, **params)

  save_result = @client.state_save(name,
                                   flow: flow.name,
                                   flow_version: flow.version_string,
                                   origins: manifest[:origins] || manifest["origins"])
  Result.new(save_result: save_result, flow_name: flow.name, flow_version: flow.version_string)
end