Sha256: 6df728b9141191f6f08344c4931e485860dc1668d25ede98e1d309ba6e543909

Contents?: true

Size: 1.31 KB

Versions: 139

Compression:

Stored size: 1.31 KB

Contents

module Eco
  module API
    class MicroCases
      # Finds all the subordinates of `supervisor`.
      # @note if `supervisor` is `nil`, it will return all people with no supervisor.
      # @param supervisor [String, Ecoportal::API::V1::Person, Hash] the `supervisor` or the `id` / `external_id` thereof.
      # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
      # @yield [subordinate] block that does some stuff with `subordinate`.
      # @yieldparam subordinate [Ecoportal::API::V1::Person] each one of the suborinates of `supervisor`.
      # @return [Eco::API::Organization::People] the **subordinates** of `supervisor`.
      def with_each_subordinate(supervisor, people)
        people.supervisor_id(_person_id(supervisor, people)).tap do |subordinates|
          subordinates.each do |subordinate|
            yield(subordinate) if block_given?
          end
        end
      end

      private

      def _person_id(value, people)
        case value
        when Hash
          _person_id(value["id"] || value["external_id"], people)
        when Ecoportal::API::V1::Person
          _person_id(value.id    || value.external_id, people)
        when String
          micro.with_supervisor(value, people)&.id
        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_each_subordinate.rb
eco-helpers-2.7.23 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.22 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.21 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.20 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.19 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.18 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.17 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.16 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.15 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.14 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.13 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.12 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.4 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.2 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.1 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.7.0 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.6.4 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.6.3 lib/eco/api/microcases/with_each_subordinate.rb
eco-helpers-2.6.2 lib/eco/api/microcases/with_each_subordinate.rb