class Linearly::Step::Static

{Static} is a type of Step whose operation solely depends on the content of the State passed to its {.call} method. It's the best and most deterministic type of a Step, hence we provided a helper. Inheriting from {Static} will still require you to implement three methods: class inputs and outputs methods, and an instance call method. What you get though is that your call method does not need to take any parameters and will have access to the private state instance variable. What's more, any unknown messages will be forwarded to state, so that your code can be shorter and more expressive. Also, you don't have to explicitly rescue exceptions - the static {.call} method will catch those and fail the state accordingly.

Attributes

state[R]

{State} received through the constructor

@return [Statefully::State] @api private

Public Class Methods

call(state) click to toggle source

Main entry point to {Step::Static}

@param state [Statefully::State]

@return [Statefully::State] @api public @example

class FindUser < Linearly::Step::Static
  def self.inputs
    { user_id: Integer }
  end

  def self.outputs
    { user: User }
  end

  def call
    succeed(user: User.find(user_id))
  end
end
FindUser.call(Statefully::State.create(user_id: params[:id]))
# File lib/linearly/step/static.rb, line 38
def self.call(state)
  new(state).call
rescue StandardError => err
  state.fail(err)
end
inputs() click to toggle source

Inputs for a step

@return [Hash<Symbol, Expectation>] @api public @example

FindUser.inputs
=> { user_id: Integer }
# File lib/linearly/step/static.rb, line 59
def self.inputs
  raise NotImplementedError
end
outputs() click to toggle source

Outputs for a step

@return [Hash<Symbol, Expectation>] @api public @example

FindUser.outputs
=> { user: User }
# File lib/linearly/step/static.rb, line 70
def self.outputs
  {}
end

Private Class Methods

new(state) click to toggle source

Constructor for the {Step::Static}

@param state [Statefully::State] @api private

# File lib/linearly/step/static.rb, line 86
def initialize(state)
  @state = state
end

Public Instance Methods

call() click to toggle source

User-defined logic for this Step

@return [Statefully::State] @api private

# File lib/linearly/step/static.rb, line 48
def call
  raise NotImplementedError
end

Private Instance Methods

method_missing(name, *args, &block) click to toggle source

Dynamically pass valid inputs to the wrapped State

@param name [Symbol|String] @param args [Array<Object>] @param block [Proc]

@return [Object] @raise [NoMethodError] @api private

Calls superclass method
# File lib/linearly/step/static.rb, line 100
def method_missing(name, *args, &block)
  allowed = [:correlation_id] + state.methods + self.class.inputs.keys
  allowed.include?(name) ? state.send(name, *args, &block) : super
end
respond_to_missing?(name, include_private = false) click to toggle source

Companion to `method_missing`

This method reeks of :reek:BooleanParameter.

@param name [Symbol|String] @param include_private [Boolean]

@return [Boolean] @api private

# File lib/linearly/step/static.rb, line 114
def respond_to_missing?(name, include_private = false)
  state.send(:respond_to_missing?, name, include_private)
end