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.67 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.66 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.65 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.64 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.63 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.62 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.61 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.60 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.59 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.58 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.57 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.56 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.55 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.54 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.53 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.52 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.51 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.50 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.49 lib/eco/api/microcases/with_supervisor.rb
eco-helpers-2.0.48 lib/eco/api/microcases/with_supervisor.rb