Module: MrDarcy::Promise::State
- Defined in:
- lib/mr_darcy/promise/state.rb,
lib/mr_darcy/promise/state/base.rb,
lib/mr_darcy/promise/state/rejected.rb,
lib/mr_darcy/promise/state/resolved.rb,
lib/mr_darcy/promise/state/unresolved.rb
Overview
Implementation of the State Pattern for Promises.
Defined Under Namespace
Classes: Base, Rejected, Resolved, Unresolved
Class Method Summary collapse
-
.state(stateful) ⇒ Object
Return an instance of the correct State class based on the state of the passed in object.
Class Method Details
.state(stateful) ⇒ Object
Return an instance of the correct State class based on the state of the passed in object.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mr_darcy/promise/state.rb', line 14 def state stateful case stateful.send :state when :unresolved Unresolved.new stateful when :resolved Resolved.new stateful when :rejected Rejected.new stateful else raise "Unknown state #{stateful.state}" end end |