Sha256: 19aa9e7ca0b16559277bfa3a2fc04d198456965c2d291b1d00703e167da1b1df
Contents?: true
Size: 1.44 KB
Versions: 23
Compression:
Stored size: 1.44 KB
Contents
module Eco module API class MicroCases # Finds the supervisor among `people` by using the `supervisor_id` of `value`. # @param value [String, Ecoportal::API::V1::Person, Hash] the subordinate person, # or the unique identifier of the supervisor to be found (preferably the `external_id`). # @param people [Eco::API::Organization::People] target existing _People_ of the current update. # @param strict [Boolean] specifies if the search should be `strict` (see {Eco::API::Organization::People#person}). # @yield [supervisor] block that does some stuff with supevisor. # @yieldparam supervisor [Ecoportal::API::V1::Person] the person object of the supervisor, or `nil` if not found. # @return [nil, Ecoportal::API::V1::Person] found `supervisor` of `value`. def with_supervisor(value, people, strict: false) if sup_id = with_supervisor_supervisor_id(value) people.person(id: sup_id, external_id: sup_id, email: sup_id, strict: strict) end.tap do |supervisor| yield(supervisor) if block_given? end end private def with_supervisor_supervisor_id(value) return nil if value.to_s.strip.empty? case when value.respond_to?(:supervisor_id) value.supervisor_id when value.is_a?(Hash) value["supervisor_id"] else value end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems