Class: Browserctl::Runner

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

Constant Summary collapse

SEARCH_PATHS =
[
  "./.browserctl/workflows",
  File.expand_path("~/.browserctl/workflows")
].freeze
SAFE_WORKFLOW_NAME =
/\A[a-zA-Z0-9_-]+\z/

Instance Method Summary collapse

Instance Method Details

#describe_workflow(name) ⇒ Hash

Returns detailed information about a workflow.

Parameters:

  • name (String)

    workflow name

Returns:

  • (Hash)

    ‘{ name:, desc:, params:, steps: }`



35
36
37
38
# File 'lib/browserctl/runner.rb', line 35

def describe_workflow(name)
  defn = fetch_workflow(name)
  { name: defn.name, desc: defn.description, params: format_params(defn), steps: defn.steps.map(&:label) }
end

#list_workflowsArray<Hash>

Lists all registered workflows from the standard search paths.

Returns:

  • (Array<Hash>)

    array of ‘{ name:, desc: }` hashes



27
28
29
30
# File 'lib/browserctl/runner.rb', line 27

def list_workflows
  load_all_workflows
  REGISTRY.map { |name, defn| { name: name, desc: defn.description } }
end

#run_workflow(name, **params) ⇒ Boolean

Runs a named workflow with the given parameters.

Parameters:

  • name (String)

    workflow name (must match /A+z/)

  • params (Hash)

    keyword arguments passed to the workflow

Returns:

  • (Boolean)

    true if all steps succeeded

Raises:



18
19
20
21
22
23
# File 'lib/browserctl/runner.rb', line 18

def run_workflow(name, **params)
  defn    = fetch_workflow(name)
  results = defn.call(params, Client.new)
  print_results(results)
  results.all?(&:ok)
end