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.0.47 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.46 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.45 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.44 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.43 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.42 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.41 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.40 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.39 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.38 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.37 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.36 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.35 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.34 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.33 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.32 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.31 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.30 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.29 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.28 lib/eco/api/microcases/with_supervisor.rb