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} received through the constructor
@return [Statefully::State] @api private
Public Class Methods
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 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 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
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
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
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
# 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
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