Class: WebFunction::Promise
- Inherits:
-
Object
- Object
- WebFunction::Promise
- Defined in:
- lib/web_function/promise.rb
Overview
A promise is a placeholder for a value that will be resolved later.
Defined Under Namespace
Classes: Path
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of the promise.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value of the promise at the given key.
-
#initialize(pipeline, path) ⇒ Promise
constructor
A new instance of Promise.
-
#resolve ⇒ Object
Resolves the promise.
-
#to_json(*args) ⇒ String
Returns the JSON representation of the promise.
-
#to_s ⇒ String
Returns the string representation of the promise.
Constructor Details
Instance Attribute Details
#value ⇒ Object
Returns the value of the promise.
128 129 130 131 132 133 134 |
# File 'lib/web_function/promise.rb', line 128 def value unless @value raise WebFunction::UnresolvedPromiseError end @value end |
Instance Method Details
#[](key) ⇒ Object
Returns the value of the promise at the given key.
114 115 116 117 118 119 120 |
# File 'lib/web_function/promise.rb', line 114 def [](key) if @value @value[key] else @path[key] end end |
#resolve ⇒ Object
Resolves the promise.
140 141 142 143 144 145 146 147 148 |
# File 'lib/web_function/promise.rb', line 140 def resolve if @value return @value end @pipeline.execute value end |
#to_json(*args) ⇒ String
Returns the JSON representation of the promise.
100 101 102 103 104 105 106 |
# File 'lib/web_function/promise.rb', line 100 def to_json(*args) if @value @value.to_json(*args) else @path.to_json(*args) end end |
#to_s ⇒ String
Returns the string representation of the promise.
86 87 88 89 90 91 92 |
# File 'lib/web_function/promise.rb', line 86 def to_s if @value @value.to_s else @path.to_s end end |