Module: DeferrableGratification::Primitives
- Included in:
- DeferrableGratification
- Defined in:
- lib/deferrable_gratification/primitives.rb
Overview
Trivial operations which return Deferrables.
Used internally by the library, and may be useful in cases where you need to return a Deferrable to keep API compatibility but the result is already available.
DeferrableGratification extends this module, and thus the methods here are accessible via the DG alias.
Instance Method Summary collapse
-
#blank ⇒ Object
Return a completely uninteresting Deferrable.
-
#const(value) ⇒ Object
Return a Deferrable which immediately succeeds, passing a constant value to callbacks.
-
#failure(exception_class_or_message, message_or_nil = nil) ⇒ Object
Return a Deferrable which immediately fails with an exception.
-
#success(*values) ⇒ Object
Return a Deferrable which immediately succeeds, passing 0 or more values to callbacks.
Instance Method Details
#blank ⇒ Object
Return a completely uninteresting Deferrable.
53 54 55 |
# File 'lib/deferrable_gratification/primitives.rb', line 53 def blank DeferrableGratification::DefaultDeferrable.new end |
#const(value) ⇒ Object
Return a Deferrable which immediately succeeds, passing a constant value to callbacks.
23 24 25 |
# File 'lib/deferrable_gratification/primitives.rb', line 23 def const(value) success(value) end |
#failure(message) ⇒ Object #failure(exception_class) ⇒ Object #failure(exception_class, message) ⇒ Object #failure(exception) ⇒ Object
Return a Deferrable which immediately fails with an exception.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/deferrable_gratification/primitives.rb', line 37 def failure(, = nil) blank.tap do |d| d.fail( case when Exception raise ArgumentError, "can't specify both exception and message" if when Class .new() else RuntimeError.new(.to_s) end) end end |
#success(*values) ⇒ Object
Return a Deferrable which immediately succeeds, passing 0 or more values to callbacks.
17 18 19 |
# File 'lib/deferrable_gratification/primitives.rb', line 17 def success(*values) blank.tap {|d| d.succeed(*values) } end |