class Statefully::State::Success

{Success} is a not-yet failed {State}.

Public Instance Methods

fail(error) click to toggle source

Return the next, failed {State} with a stored error

@param error [StandardError] error to store

@return [State::Failure] new failed {State} @api public @example

Statefully::State.create(key: 'val').fail(RuntimeError.new('Boom!'))
=> #<Statefully::State::Failure key="val", error="#<RuntimeError: Boom!>">
# File lib/statefully/state.rb, line 375
def fail(error)
  Failure.send(:new, _members, error, previous: self).freeze
end
finish() click to toggle source

Return the next, finished? {State}

@return [State::State] new finished {State} @api public @example

Statefully::State.create(key: 'val').finish
=> #<Statefully::State::Finished key="val">
# File lib/statefully/state.rb, line 386
def finish
  Finished.send(:new, _members, previous: self).freeze
end
succeed(**values) click to toggle source

Return the next, successful {State} with new values merged in (if any)

@param values [Hash<Symbol, Object>] New values of the {State}

@return [State::Success] new successful {State} @api public @example

Statefully::State.create.succeed(key: 'val')
=> #<Statefully::State::Success key="val">
# File lib/statefully/state.rb, line 362
def succeed(**values)
  self.class.send(:new, _members.merge(values).freeze, previous: self)
end