Class: Result
- Inherits:
-
Object
- Object
- Result
- Defined in:
- lib/trk/result_and_error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(message, data = {}) ⇒ Result
constructor
Use this to class to return results from service:.
- #success? ⇒ Boolean
Constructor Details
#initialize(message, data = {}) ⇒ Result
Use this to class to return results from service:
class MyService
def perform
if true
Result.new "Next task created", next_task: next_task
else
Error.new "Failed"
end
end
end
and use in controller:
result = MyService.new.perform
if result.success?
flash[:notice] = result.
redirect_to result.data[:next_task]
end
Note when iterating a huge objects, use ‘next_task_id` so Ruby Garbage Collector can clear all temp objects from the service run If you return some object which is not basic, it can not safely clear all temp objects
29 30 31 |
# File 'lib/trk/result_and_error.rb', line 29 def initialize(, data = {}) , @data = , data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
2 3 4 |
# File 'lib/trk/result_and_error.rb', line 2 def data @data end |
#message ⇒ Object
Returns the value of attribute message.
2 3 4 |
# File 'lib/trk/result_and_error.rb', line 2 def end |
Instance Method Details
#success? ⇒ Boolean
33 34 35 |
# File 'lib/trk/result_and_error.rb', line 33 def success? true end |