Class: PurePromise::Coercer
- Inherits:
-
Object
- Object
- PurePromise::Coercer
- Defined in:
- lib/pure_promise/coercer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #coerce ⇒ Object
-
#initialize(thenable, promise_class) ⇒ Coercer
constructor
A new instance of Coercer.
Constructor Details
#initialize(thenable, promise_class) ⇒ Coercer
Returns a new instance of Coercer.
16 17 18 19 20 |
# File 'lib/pure_promise/coercer.rb', line 16 def initialize(thenable, promise_class) raise TypeError, 'Can only coerce a thenable' unless self.class.is_thenable?(thenable) @thenable = thenable @promise_class = promise_class end |
Class Method Details
.coerce(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/pure_promise/coercer.rb', line 12 def self.coerce(*args, &block) new(*args, &block).coerce end |
.is_thenable?(thenable) ⇒ Boolean
8 9 10 |
# File 'lib/pure_promise/coercer.rb', line 8 def self.is_thenable?(thenable) thenable.respond_to?(:then) end |
Instance Method Details
#coerce ⇒ Object
22 23 24 25 26 27 |
# File 'lib/pure_promise/coercer.rb', line 22 def coerce return @thenable if @thenable.instance_of?(@promise_class) @mutated = false coerce_thenable end |