Class: Browserctl::Flow
- Inherits:
-
CallableDefinition
- Object
- CallableDefinition
- Browserctl::Flow
- Defined in:
- lib/browserctl/flow.rb
Constant Summary collapse
- SEMVER_RE =
/\A\d+\.\d+\.\d+\z/
Instance Attribute Summary collapse
-
#min_browserctl_version ⇒ Object
readonly
Returns the value of attribute min_browserctl_version.
-
#postconditions ⇒ Object
readonly
Returns the value of attribute postconditions.
-
#preconditions ⇒ Object
readonly
Returns the value of attribute preconditions.
-
#produces_state_block ⇒ Object
readonly
Returns the value of attribute produces_state_block.
-
#version_string ⇒ Object
readonly
Returns the value of attribute version_string.
Attributes inherited from CallableDefinition
#description, #name, #param_defs, #steps
Instance Method Summary collapse
- #callable_kind ⇒ Object
-
#compose(target_name) ⇒ Object
Definition-time guard against cross-type composition.
-
#initialize(name) ⇒ Flow
constructor
A new instance of Flow.
- #postcondition(label = "postcondition", &block) ⇒ Object
- #precondition(label = "precondition", &block) ⇒ Object
- #produces_state(&block) ⇒ Object
- #requires_browserctl(value) ⇒ Object
- #run(page: nil, client: nil, **params) ⇒ Object
- #version(value) ⇒ Object
Methods inherited from CallableDefinition
Constructor Details
#initialize(name) ⇒ Flow
Returns a new instance of Flow.
42 43 44 45 46 47 48 49 |
# File 'lib/browserctl/flow.rb', line 42 def initialize(name) super @version_string = "0.0.0" @preconditions = [] @postconditions = [] @produces_state_block = nil @min_browserctl_version = nil end |
Instance Attribute Details
#min_browserctl_version ⇒ Object (readonly)
Returns the value of attribute min_browserctl_version.
36 37 38 |
# File 'lib/browserctl/flow.rb', line 36 def min_browserctl_version @min_browserctl_version end |
#postconditions ⇒ Object (readonly)
Returns the value of attribute postconditions.
36 37 38 |
# File 'lib/browserctl/flow.rb', line 36 def postconditions @postconditions end |
#preconditions ⇒ Object (readonly)
Returns the value of attribute preconditions.
36 37 38 |
# File 'lib/browserctl/flow.rb', line 36 def preconditions @preconditions end |
#produces_state_block ⇒ Object (readonly)
Returns the value of attribute produces_state_block.
36 37 38 |
# File 'lib/browserctl/flow.rb', line 36 def produces_state_block @produces_state_block end |
#version_string ⇒ Object (readonly)
Returns the value of attribute version_string.
36 37 38 |
# File 'lib/browserctl/flow.rb', line 36 def version_string @version_string end |
Instance Method Details
#callable_kind ⇒ Object
51 52 53 |
# File 'lib/browserctl/flow.rb', line 51 def callable_kind :flow end |
#compose(target_name) ⇒ Object
Definition-time guard against cross-type composition. A flow may only compose other flows; pulling steps from a workflow would smuggle ‘store`/`fetch` into a flow context that has no daemon-backed persistence.
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/browserctl/flow.rb', line 87 def compose(target_name) name = target_name.to_s if Browserctl.respond_to?(:lookup_workflow) && Browserctl.lookup_workflow(name) raise ArgumentError, "flow '#{@name}' cannot compose workflow '#{name}': flows return state, " \ "workflows share state — composition across kinds is not supported" end source = Browserctl.lookup_flow(name) raise ArgumentError, "flow '#{name}' not found for composition" unless source @steps.concat(source.steps) end |
#postcondition(label = "postcondition", &block) ⇒ Object
71 72 73 74 75 |
# File 'lib/browserctl/flow.rb', line 71 def postcondition(label = "postcondition", &block) raise ArgumentError, "postcondition '#{label}' requires a block" unless block @postconditions << FlowConditionDef.new(kind: :postcondition, label: label, block: block) end |
#precondition(label = "precondition", &block) ⇒ Object
65 66 67 68 69 |
# File 'lib/browserctl/flow.rb', line 65 def precondition(label = "precondition", &block) raise ArgumentError, "precondition '#{label}' requires a block" unless block @preconditions << FlowConditionDef.new(kind: :precondition, label: label, block: block) end |
#produces_state(&block) ⇒ Object
77 78 79 80 81 |
# File 'lib/browserctl/flow.rb', line 77 def produces_state(&block) raise ArgumentError, "produces_state requires a block" unless block @produces_state_block = block end |
#requires_browserctl(value) ⇒ Object
60 61 62 63 |
# File 'lib/browserctl/flow.rb', line 60 def requires_browserctl(value) validate_semver!(value, label: "requires_browserctl") @min_browserctl_version = value.to_s end |
#run(page: nil, client: nil, **params) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/browserctl/flow.rb', line 101 def run(page: nil, client: nil, **params) ctx = FlowContext.new(page: page, client: client, params: resolve_params(params)) run_conditions(ctx, @preconditions, error_class: FlowPreconditionError) run_steps(ctx) run_conditions(ctx, @postconditions, error_class: FlowPostconditionError) produce_state(ctx) end |
#version(value) ⇒ Object
55 56 57 58 |
# File 'lib/browserctl/flow.rb', line 55 def version(value) validate_semver!(value, label: "version") @version_string = value.to_s end |