Class: WorkflowTemplate::Outcome::Statuses
- Inherits:
-
Object
- Object
- WorkflowTemplate::Outcome::Statuses
- Defined in:
- lib/workflow_template/outcome/statuses.rb
Instance Method Summary collapse
- #all_defaults! ⇒ Object
- #default!(status) ⇒ Object
- #default_missing ⇒ Object
- #default_missing? ⇒ Boolean
- #handled!(status) ⇒ Object
-
#initialize(ok: Status.new, error: Status.new) ⇒ Statuses
constructor
A new instance of Statuses.
- #inspect ⇒ Object
- #on_default_detected(status, detected) ⇒ Object
- #status(status) ⇒ Object (also: #[])
- #unhandled?(status) ⇒ Boolean
Constructor Details
Instance Method Details
#all_defaults! ⇒ Object
51 52 53 |
# File 'lib/workflow_template/outcome/statuses.rb', line 51 def all_defaults! self.class.new(**@statuses.transform_values(&:default!)) end |
#default!(status) ⇒ Object
46 47 48 49 |
# File 'lib/workflow_template/outcome/statuses.rb', line 46 def default!(status) updated = status(status).default! self.class.new(**@statuses, status => updated) end |
#default_missing ⇒ Object
29 30 31 |
# File 'lib/workflow_template/outcome/statuses.rb', line 29 def default_missing @statuses.reject { |_, status| status.default? }.keys end |
#default_missing? ⇒ Boolean
25 26 27 |
# File 'lib/workflow_template/outcome/statuses.rb', line 25 def default_missing? @statuses.none? { |_, status| status.default? } end |
#handled!(status) ⇒ Object
35 36 37 38 |
# File 'lib/workflow_template/outcome/statuses.rb', line 35 def handled!(status) updated = status(status).handled! self.class.new(**@statuses, status => updated) end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/workflow_template/outcome/statuses.rb', line 55 def inspect "#<#{self.class.name} #{@statuses.map { |name, status| "#{name}: #{status.inspect}" }}>" end |
#on_default_detected(status, detected) ⇒ Object
40 41 42 43 44 |
# File 'lib/workflow_template/outcome/statuses.rb', line 40 def on_default_detected(status, detected) return self unless detected default!(status) end |
#status(status) ⇒ Object Also known as: []
14 15 16 17 18 19 |
# File 'lib/workflow_template/outcome/statuses.rb', line 14 def status(status) status = status.to_sym raise Error, "Unsupported status: '#{status}'" unless @statuses.key? status @statuses[status] end |
#unhandled?(status) ⇒ Boolean
21 22 23 |
# File 'lib/workflow_template/outcome/statuses.rb', line 21 def unhandled?(status) !status(status).handled? end |