How to access result original service?
The Result#service
method returns the service instance that created its result.
For example:
class Service
include ConvenientService::Standard::Config
def result
success
end
end
result = Service.result
# => <Service::Result status: :success>
result.service
# => <Service>
When the result is bubbled up from a deeply nested step, the Result#service
method returns a top-level organizer instance.
Let's see it in practice:
class TwoLevelsNestedService
include ConvenientService::Standard::Config
def result
success
end
end
class OneLevelNestedService
include ConvenientService::Standard::Config
step TwoLevelsNestedService
end
class Service
include ConvenientService::Standard::Config
step OneLevelNestedService
end
result = Service.result
# => <Service::Result status: :success>
result.service
# => <Service>
Here, the TwoLevelsNestedService
creates a success
result.
Later this result is processed by steps from the OneLevelNestedService
and Service
services.
That is why it becomes the Service
overall result.
result.service
# => <Service>
Sometimes it may be useful to access the original service instance, e.g. for debugging purposes.
For that reason the Result#original_service
method is available.
result.original_service
# => <TwoLevelsNestedService>