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!>">

351
352
353
# File 'lib/statefully/state.rb', line 351

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">

362
363
364
# File 'lib/statefully/state.rb', line 362

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">

338
339
340
# File 'lib/statefully/state.rb', line 338

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