Sha256: 0285400c2adfd4b5a451f9bc0acf5b93fe647055ab4506d19afd153398ecd5d7

Contents?: true

Size: 1.45 KB

Versions: 139

Compression:

Stored size: 1.45 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

139 entries across 139 versions & 1 rubygems

Version Path
eco-helpers-2.7.24 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.23 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.22 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.21 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.20 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.19 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.18 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.17 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.16 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.15 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.14 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.13 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.12 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.4 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.2 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.1 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.7.0 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.6.4 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.6.3 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.6.2 lib/eco/api/microcases/with_supervisor.rb