Class: Statefully::State::Success

Inherits:
Statefully::State show all
Defined in:
lib/statefully/state.rb

Overview

Success is a not-yet failed Statefully::State.

Instance Attribute Summary

Attributes inherited from Statefully::State

#previous

Instance Method Summary collapse

Methods inherited from Statefully::State

create, #diff, #each, #failed?, #fetch, #finished?, #history, #inspect, #key?, #keys, #none?, #resolve, #successful?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Statefully::State

Instance Method Details

#fail(error) ⇒ State::Failure

Return the next, failed Statefully::State with a stored error

Examples:

Statefully::State.create(key: 'val').fail(RuntimeError.new('Boom!'))
=> #<Statefully::State::Failure key="val", error="#<RuntimeError: Boom!>">

Parameters:

  • error (StandardError)

    error to store

Returns:



353
354
355
# File 'lib/statefully/state.rb', line 353

def fail(error)
  Failure.send(:new, _members, error, previous: self).freeze
end

#finishState::State

Return the next, finished? Statefully::State

Examples:

Statefully::State.create(key: 'val').finish
=> #<Statefully::State::Finished key="val">

Returns:



364
365
366
# File 'lib/statefully/state.rb', line 364

def finish
  Finished.send(:new, _members, previous: self).freeze
end

#succeed(**values) ⇒ State::Success

Return the next, successful Statefully::State with new values merged in (if any)

Examples:

Statefully::State.create.succeed(key: 'val')
=> #<Statefully::State::Success key="val">

Parameters:

Returns:



340
341
342
# File 'lib/statefully/state.rb', line 340

def succeed(**values)
  self.class.send(:new, _members.merge(values).freeze, previous: self)
end