Module: Operatic
- Defined in:
- lib/operatic.rb,
lib/operatic/data.rb,
lib/operatic/errors.rb,
lib/operatic/result.rb,
lib/operatic/version.rb
Defined Under Namespace
Modules: ClassMethods Classes: Data, Failure, Result, Success
Constant Summary collapse
- OperaticError =
Class.new(StandardError)
- FailureError =
Class.new(OperaticError)
- VERSION =
'0.7.0'
Instance Attribute Summary collapse
- #result ⇒ Success, Failure readonly
Instance Method Summary collapse
-
#call ⇒ Object
Override this method with your implementation.
-
#data ⇒ Data
Any data to be communicated via the operation’s result should be added to this Data object.
-
#failure!(**kwargs) ⇒ Object
Mark the operation as a failure and prevent further modification to the operation, its result, and its data.
- #freeze ⇒ self
- #initialize(**attrs) ⇒ Object
-
#success!(**kwargs) ⇒ Object
Mark the operation as a success and prevent further modification to the operation, its result, and its data.
Instance Attribute Details
Instance Method Details
#call ⇒ Object
108 109 |
# File 'lib/operatic.rb', line 108 def call end |
#data ⇒ Data
Any data to be communicated via the operation’s result should be added to this Data object.
Note: This will be frozen when returned from an operation.
130 131 132 |
# File 'lib/operatic.rb', line 130 def data @data ||= self.class.data_class.new end |
#failure!(**kwargs) ⇒ Object
Mark the operation as a failure and prevent further modification to the operation, its result, and its data.
140 141 142 143 |
# File 'lib/operatic.rb', line 140 def failure!(**kwargs) @result = Failure.new(data.merge(kwargs)) freeze end |
#freeze ⇒ self
146 147 148 149 |
# File 'lib/operatic.rb', line 146 def freeze @result.freeze super end |
#initialize(**attrs) ⇒ Object
77 78 79 80 81 |
# File 'lib/operatic.rb', line 77 def initialize(**attrs) attrs.each do |key, value| instance_variable_set("@#{key}", value) end end |