Class: Plutonium::Interaction::Outcome Abstract
- Inherits:
-
Object
- Object
- Plutonium::Interaction::Outcome
- Defined in:
- lib/plutonium/interaction/outcome.rb
Overview
This class is abstract.
Subclass and override #and_then, #map, and #to_response to implement
Base class for interaction outcomes.
This class provides a common interface for both successful and failed outcomes of an interaction.
Defined Under Namespace
Instance Method Summary collapse
-
#and_then ⇒ Object
abstract
Chains another operation to be executed if this outcome is successful.
-
#failure? ⇒ Boolean
Checks if the outcome is a failure.
- #messages ⇒ Object
-
#success? ⇒ Boolean
Checks if the outcome is successful.
-
#to_response ⇒ Object
abstract
Converts the outcome to a response object.
-
#with_message(msg, type = :notice) ⇒ self
Adds a message to the outcome.
-
#with_response(response) ⇒ Object
abstract
Sets the response for the outcome.
Instance Method Details
#and_then ⇒ Object
This method is abstract.
Chains another operation to be executed if this outcome is successful.
51 52 53 |
# File 'lib/plutonium/interaction/outcome.rb', line 51 def and_then raise NotImplementedError, "#{self.class} must implement #and_then" end |
#failure? ⇒ Boolean
Checks if the outcome is a failure.
22 23 24 |
# File 'lib/plutonium/interaction/outcome.rb', line 22 def failure? is_a?(Failure) end |
#messages ⇒ Object
10 |
# File 'lib/plutonium/interaction/outcome.rb', line 10 def = @messages || [] |
#success? ⇒ Boolean
Checks if the outcome is successful.
15 16 17 |
# File 'lib/plutonium/interaction/outcome.rb', line 15 def success? is_a?(Success) end |
#to_response ⇒ Object
This method is abstract.
Converts the outcome to a response object.
59 60 61 |
# File 'lib/plutonium/interaction/outcome.rb', line 59 def to_response raise NotImplementedError, "#{self.class} must implement #to_response" end |
#with_message(msg, type = :notice) ⇒ self
Adds a message to the outcome.
31 32 33 34 35 |
# File 'lib/plutonium/interaction/outcome.rb', line 31 def (msg, type = :notice) @messages ||= [] @messages << [msg, type] self end |
#with_response(response) ⇒ Object
This method is abstract.
Sets the response for the outcome.
43 44 45 |
# File 'lib/plutonium/interaction/outcome.rb', line 43 def with_response(response) raise NotImplementedError, "#{self.class} must implement #with_response" end |