Class: Browserctl::CallableDefinition

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

Overview

Shared base for Flow and WorkflowDefinition. Holds the duplicated DSL surface (‘desc`, `param`, `step`) and the shared execution helpers for resolving params and running step blocks with retry + timeout.

Subclasses provide:

  • their own ‘call`/`run` entry point and context object;

  • #callable_kind so cross-type composition can be rejected at definition time (e.g. a flow trying to ‘compose` a workflow);

  • #step_failure_message for the typed error wording.

The persistence DSL (‘store`/`fetch`/`save_state`/`load_state`) is mixed into `WorkflowContext` via ContextualPersistence and is deliberately absent from `FlowContext` — flows return state, workflows share state.

Direct Known Subclasses

Flow, WorkflowDefinition

Defined Under Namespace

Classes: ParamDef, StepDef

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CallableDefinition

Returns a new instance of CallableDefinition.



28
29
30
31
32
33
# File 'lib/browserctl/callable_definition.rb', line 28

def initialize(name)
  @name        = name.to_s
  @description = nil
  @param_defs  = {}
  @steps       = []
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



26
27
28
# File 'lib/browserctl/callable_definition.rb', line 26

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



26
27
28
# File 'lib/browserctl/callable_definition.rb', line 26

def name
  @name
end

#param_defsObject (readonly)

Returns the value of attribute param_defs.



26
27
28
# File 'lib/browserctl/callable_definition.rb', line 26

def param_defs
  @param_defs
end

#stepsObject (readonly)

Returns the value of attribute steps.



26
27
28
# File 'lib/browserctl/callable_definition.rb', line 26

def steps
  @steps
end

Instance Method Details

#callable_kindSymbol

Returns :flow or :workflow — used for cross-type composition checks.

Returns:

  • (Symbol)

    :flow or :workflow — used for cross-type composition checks.

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/browserctl/callable_definition.rb', line 59

def callable_kind
  raise NotImplementedError
end

#desc(text) ⇒ Object



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

def desc(text)
  @description = text.to_s
end

#param(name, required: false, secret: false, default: nil, secret_ref: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/browserctl/callable_definition.rb', line 39

def param(name, required: false, secret: false, default: nil, secret_ref: nil)
  secret = true if secret_ref
  @param_defs[name] = ParamDef.new(
    name: name,
    required: required,
    secret: secret,
    default: default,
    secret_ref: secret_ref
  )
end

#step(label, retry_count: 0, timeout: nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
# File 'lib/browserctl/callable_definition.rb', line 50

def step(label, retry_count: 0, timeout: nil, &block)
  raise ArgumentError, "#{callable_kind} step '#{label}' requires a block" unless block

  @steps << StepDef.new(label: label, block: block, retry_count: retry_count, timeout: timeout)
end