Class: Linearly::Flow

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Mixins::StepCollection
Defined in:
lib/linearly/flow.rb

Instance Method Summary collapse

Constructor Details

#initialize(*steps) ⇒ Flow

Constructor for the Linearly::Flow

Examples:

flow = Linearly::Flow.new(
  Users::Find,
  Users::AddRole.new(:admin),
  Users::Save,
)

Parameters:

  • steps (Array<Step>)

    array of things that implement the Step interface (call, inputs and outputs methods).



54
55
56
57
# File 'lib/linearly/flow.rb', line 54

def initialize(*steps)
  @steps = steps
  @contract = Contract.new(steps)
end

Instance Method Details

#>>(other) ⇒ Flow

Convenience method to join Steps into one Linearly::Flow

Examples:

flow =
  Users::Find
  .>> Users::Update
  .>> Users::Save

Parameters:

Returns:



70
71
72
# File 'lib/linearly/flow.rb', line 70

def >>(other)
  Flow.new(other, *@steps)
end

#call(state) ⇒ Statefully::State

Validate the input state and run steps as long as it’s a Success

Examples:

flow = Linearly::Flow.new(
  Users::Find,
  Users::AddRole.new(:admin),
  Users::Save,
)
flow.call(Statefully::State.create(user_id: params[:id]))

Parameters:

  • state (Statefully::State)

Returns:

  • (Statefully::State)


40
# File 'lib/linearly/flow.rb', line 40

def_delegators :@contract, :inputs, :outputs

#inputsHash<Symbol, TrueClass>

Inputs required for the Linearly::Flow

Examples:

Linearly::Flow.new(Users::Find).inputs
=> {user_id: true}

Returns:

  • (Hash<Symbol, TrueClass>)


40
# File 'lib/linearly/flow.rb', line 40

def_delegators :@contract, :inputs, :outputs

#outputsHash<Symbol, TrueClass>

Outputs provided by the Linearly::Flow

Examples:

Linearly::Flow.new(Users::Find).outputs
=> {user: true}

Returns:

  • (Hash<Symbol, TrueClass>)


40
# File 'lib/linearly/flow.rb', line 40

def_delegators :@contract, :inputs, :outputs