Module: Operatic::ClassMethods
- Defined in:
- lib/operatic.rb
Instance Method Summary collapse
-
#call(**attrs) ⇒ Result
The main way of calling an operation.
-
#call!(**attrs) ⇒ Result
Calls #call but raises FailureError if the returned Result is a Result#failure? - useful for things like background jobs, rake tasks, test setups, etc.
-
#result_attr(*attrs) ⇒ Object
Define a Result subclass with named accessors specific to the class via Result.generate.
- #result_class ⇒ Object
Instance Method Details
#call(**attrs) ⇒ Result
The main way of calling an operation.
The class is instantiated with the supplied attrs keyword arguments and
calls Operatic#call returning a frozen Result instance.
18 19 20 21 22 23 |
# File 'lib/operatic.rb', line 18 def call(**attrs) new(**attrs) .tap(&:call) .result .freeze end |
#call!(**attrs) ⇒ Result
Calls #call but raises FailureError if the returned Result is a Result#failure? - useful for things like background jobs, rake tasks, test setups, etc.
30 31 32 33 34 |
# File 'lib/operatic.rb', line 30 def call!(**attrs) call(**attrs).tap { |result| raise FailureError if result.failure? } end |
#result_attr(*attrs) ⇒ Object
Define a Result subclass with named accessors specific to the class via Result.generate.
58 59 60 |
# File 'lib/operatic.rb', line 58 def result_attr(*attrs) @result_class = Result.generate(*attrs) end |
#result_class ⇒ Object
62 63 64 |
# File 'lib/operatic.rb', line 62 def result_class @result_class || Result end |