Sha256: fe6e3511fb94b79d4c95b775abefdde6d5988151332e933ec6ba0b9eb72940ea

Contents?: true

Size: 1.36 KB

Versions: 37

Compression:

Stored size: 1.36 KB

Contents

module Eco
  module API
    class MicroCases
      # Special snippet to decide if the `supervisor_id` is set now or in a later batch job `supers_job`.
      # @note delaying the setting of a `supervisor_id` can save errors when the supervisor still does not exit.
      # @param sup_id [nil, String] the **supervisor id** we should set on the `person`.
      # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
      # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
      # @param options [Hash] the options.
      # @yield [supervisor_id] callback when the supervisor_id is **unknown** (not `nil` nor any one's in `people`).
      # @yieldparam supervisor_id [String] the **unknown** `supervisor_id`.
      def set_supervisor(sup_id, person, people, options)
        unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
          micro.with_supervisor(sup_id, people) do |supervisor|
            if !sup_id
              person.supervisor_id = nil
            elsif supervisor
              person.supervisor_id = supervisor.id
            elsif !block_given?
              person.supervisor_id = sup_id
            else
              yield(sup_id) if block_given?
            end
          end
        end
      end

    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
eco-helpers-2.0.25 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.24 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.23 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.22 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.21 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.19 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.18 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.17 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.16 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.15 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.14 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.13 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.12 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.11 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.10 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.9 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.8 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.7 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.6 lib/eco/api/microcases/set_supervisor.rb
eco-helpers-2.0.5 lib/eco/api/microcases/set_supervisor.rb