Module: ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern

Includes:
ConvenientService::Support::Concern
Defined in:
lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_own_result/concern.rb

Instance Method Summary collapse

Instance Method Details

#foreign_result_for?(service) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks whether a result is a foreign result for a service instance. Opposite to own result.

Parameters:

Returns:

  • (Boolean)


130
131
132
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_own_result/concern.rb', line 130

def foreign_result_for?(service)
  !own_result_for?(service)
end

#own_result_for?(service) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks whether a result is an own result for a service instance. If the result is own then it is one of success, failure, error or step result. Otherwise it is foreign for that particular service instance.

Examples:

success, failure and error are own results for service instance.

class Service
  include ConvenientService::Standard::Config

  def result
    success
  end
end

first_service = Service.new
second_service = Service.new

first_service.result.own_result_for?(first_service)
# => true

second_service.result.own_result_for?(first_service)
# => false

Service step results are own results for service instance.

class Service
  include ConvenientService::Standard::Config

  step OtherService
end

first_service = Service.new
second_service = Service.new

first_service.steps.first.result.own_result_for?(first_service)
# => true

second_service.steps.first.result.own_result_for?(first_service)
# => false

Method step results are own results for service instance.

class Service
  include ConvenientService::Standard::Config

  step :foo

  def foo
    success
  end
end

first_service = Service.new
second_service = Service.new

first_service.steps.first.result.own_result_for?(first_service)
# => true

second_service.steps.first.result.own_result_for?(first_service)
# => false

All results that are NOT any of success, failure, error or step results are NOT own results for service instance. Such results are called foreign service results.

class Service
  include ConvenientService::Standard::Config

  def result
    OtherService.result
  end
end

first_service = Service.new
second_service = Service.new

first_service.result.own_result_for?(first_service)
# => false

second_service.result.own_result_for?(first_service)
# => false

Edge case: Step results are always own even when method step result calls foreign service result.

class Service
  include ConvenientService::Standard::Config

  step :foo

  def foo
    OtherService.result
  end
end

first_service = Service.new
second_service = Service.new

first_service.result.own_result_for?(first_service)
# => true

second_service.result.own_result_for?(first_service)
# => false

Parameters:

Returns:

  • (Boolean)


117
118
119
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_own_result/concern.rb', line 117

def own_result_for?(service)
  self.service.equal?(service)
end