Class: ConvenientService::Service::Plugins::SetsParentToForeignResult::Middleware

Inherits:
MethodChainMiddleware
  • Object
show all
Defined in:
lib/convenient_service/service/plugins/sets_parent_to_foreign_result/middleware.rb

Instance Method Summary collapse

Instance Method Details

#nextConvenientService::Service::Plugins::HasJSendResult::Entities::Result

Examples:

Behavior when ‘SetsParentToForeignResult` middleware is NOT used.


class Service
  def result
    OtherService.result
  end
end

service = Service.new

service.result
# => Result.new(service: instance_of(OtherService), parent: instance_of(OtherService).parent)

Behavior when ‘SetsParentToForeignResult` middleware is used.


class Service
  def result
    OtherService.result
  end
end

service = Service.new

service.result
# => Result.new(service: instance_of(Service), parent: instance_of(OtherService))

Returns:



45
46
47
48
49
50
51
# File 'lib/convenient_service/service/plugins/sets_parent_to_foreign_result/middleware.rb', line 45

def next(...)
  result = chain.next(...)

  return result unless result.foreign_result_for?(entity)

  result.copy(overrides: {kwargs: {service: entity, step: nil, parent: result}})
end