Class: Outbacker::OutcomeHandlerSet
- Inherits:
-
Struct
- Object
- Struct
- Outbacker::OutcomeHandlerSet
- Defined in:
- lib/outbacker.rb
Overview
Class to encapsulate the processing of a block of outcome handlers.
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#handled_outcome ⇒ Object
Returns the value of attribute handled_outcome.
-
#outcome_handlers ⇒ Object
Returns the value of attribute outcome_handlers.
-
#triggered_outcome ⇒ Object
Returns the value of attribute triggered_outcome.
Instance Method Summary collapse
-
#handle(outcome_key, *args) ⇒ Object
Process the outcome specified by the given outcome_key, using the outcome handlers set on this OutcomeHandlerSet instance.
-
#method_missing(method_name, *args, &outcome_block) ⇒ Object
Provides an alternate way to specify a callback block using method names.
-
#of(outcome_key, &outcome_block) ⇒ Object
Specify an outcome handler callback block for the specified outcome key.
-
#outcome_handled? ⇒ Boolean
Internal method to indicate that the outcome has been handled by some han dler.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &outcome_block) ⇒ Object
Provides an alternate way to specify a callback block using method names.
80 81 82 83 84 85 |
# File 'lib/outbacker.rb', line 80 def method_missing(method_name, *args, &outcome_block) super unless /^outcome_of_(?<suffix>.*)/ =~ method_name.to_s outcome_key = suffix.to_sym execute_outcome_block(outcome_key, &outcome_block) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args
38 39 40 |
# File 'lib/outbacker.rb', line 38 def args @args end |
#handled_outcome ⇒ Object
Returns the value of attribute handled_outcome
38 39 40 |
# File 'lib/outbacker.rb', line 38 def handled_outcome @handled_outcome end |
#outcome_handlers ⇒ Object
Returns the value of attribute outcome_handlers
38 39 40 |
# File 'lib/outbacker.rb', line 38 def outcome_handlers @outcome_handlers end |
#triggered_outcome ⇒ Object
Returns the value of attribute triggered_outcome
38 39 40 |
# File 'lib/outbacker.rb', line 38 def triggered_outcome @triggered_outcome end |
Instance Method Details
#handle(outcome_key, *args) ⇒ Object
Process the outcome specified by the given outcome_key, using the outcome handlers set on this OutcomeHandlerSet instance. Any additiona arbitrary arguments can be passed through to the corresponding outcome handler callback.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/outbacker.rb', line 49 def handle(outcome_key, *args) self.triggered_outcome = outcome_key self.args = args if outcome_handlers outcome_handlers.call(self) raise "No outcome handler for outcome #{outcome_key}" unless outcome_handled? end true end |
#of(outcome_key, &outcome_block) ⇒ Object
Specify an outcome handler callback block for the specified outcome key.
72 73 74 |
# File 'lib/outbacker.rb', line 72 def of(outcome_key, &outcome_block) execute_outcome_block(outcome_key, &outcome_block) end |
#outcome_handled? ⇒ Boolean
Internal method to indicate that the outcome has been handled by some han dler.
64 65 66 |
# File 'lib/outbacker.rb', line 64 def outcome_handled? !!self.handled_outcome end |