class TheHelp::Service::Result
Holds the result of running a service as well as the execution status
An instance of this class will be returned from any service call and will have a status of either :success or :error along with a value that is set by the service.
Attributes
status[RW]
value[RW]
Public Class Methods
new()
click to toggle source
# File lib/the_help/service.rb, line 198 def initialize self.status = :pending self.value = nil end
Public Instance Methods
error(value = nil, &block)
click to toggle source
# File lib/the_help/service.rb, line 221 def error(value = nil, &block) self.value = if block_given? begin self.value = block.call rescue StandardError => e e end else value end self.status = :error freeze end
error?()
click to toggle source
# File lib/the_help/service.rb, line 211 def error? status == :error end
pending?()
click to toggle source
# File lib/the_help/service.rb, line 203 def pending? status == :pending end
success(value = nil)
click to toggle source
# File lib/the_help/service.rb, line 215 def success(value = nil) self.value = value self.status = :success freeze end
success?()
click to toggle source
# File lib/the_help/service.rb, line 207 def success? status == :success end
value!()
click to toggle source
# File lib/the_help/service.rb, line 235 def value! raise TheHelp::NoResultError if pending? raise value if error? && value.is_a?(Exception) raise TheHelp::ResultError.new(value) if error? value end