Class: NextStation::Operation::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/next_station/operation/node.rb

Overview

Represents a node in the operation’s execution graph (step or branch).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name = nil, options = {}) { ... } ⇒ Node

Returns a new instance of Node.

Parameters:

  • type (Symbol)

    :step, :branch, or :root.

  • name (Symbol, nil) (defaults to: nil)

    The name of the step.

  • options (Hash) (defaults to: {})

    Execution options.

Yields:

  • The block for branch nodes.



20
21
22
23
24
25
26
# File 'lib/next_station/operation/node.rb', line 20

def initialize(type, name = nil, options = {}, &block)
  @type = type
  @name = name
  @options = options
  @children = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#childrenArray<Node> (readonly)

Returns Child nodes (for branches or root).

Returns:

  • (Array<Node>)

    Child nodes (for branches or root).



14
15
16
# File 'lib/next_station/operation/node.rb', line 14

def children
  @children
end

#nameSymbol? (readonly)

Returns The name of the step.

Returns:

  • (Symbol, nil)

    The name of the step.



10
11
12
# File 'lib/next_station/operation/node.rb', line 10

def name
  @name
end

#optionsHash (readonly)

Returns Execution options.

Returns:

  • (Hash)

    Execution options.



12
13
14
# File 'lib/next_station/operation/node.rb', line 12

def options
  @options
end

#typeSymbol (readonly)

Returns The node type (:step, :branch, or :root).

Returns:

  • (Symbol)

    The node type (:step, :branch, or :root).



8
9
10
# File 'lib/next_station/operation/node.rb', line 8

def type
  @type
end

Instance Method Details

#add_child(node) ⇒ Object

Adds a child node.

Parameters:



30
31
32
# File 'lib/next_station/operation/node.rb', line 30

def add_child(node)
  @children << node
end

#branch(condition) { ... } ⇒ Object

Adds a branch to the node.

Parameters:

  • condition (Proc)

    A proc that receives the state and returns a boolean.

Yields:

  • The block defining steps inside the branch.



44
45
46
# File 'lib/next_station/operation/node.rb', line 44

def branch(condition, &block)
  @children << Node.new(:branch, nil, { condition: condition }, &block)
end

#step(name, options = {}) ⇒ Object

Adds a step to the node.

Parameters:

  • name (Symbol)

    The method name to execute.

  • options (Hash) (defaults to: {})

    Execution options like :skip_if, :retry_if, :attempts, :delay.



37
38
39
# File 'lib/next_station/operation/node.rb', line 37

def step(name, options = {})
  @children << Node.new(:step, name, options)
end