Sha256: 5000cc41988f6b9fdc7cebd3cb48894766d100c85beee1c07ea90da1b4254f7f

Contents?: true

Size: 1.4 KB

Versions: 30

Compression:

Stored size: 1.4 KB

Contents

module Eco
  module API
    class MicroCases
      # Detects who in the `entries` is new in the organization and `yield` s them one by one to the given block.
      # @note
      #   - it also links to `person.entry` the input data `entry`.
      # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
      # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
      # @param options [Hash] the options.
      # @param log_present [Boolean] log error message if an `entry` has match in `people`.
      # @yield [entry, person] gives each **new** `person` of `entries` that is not present in `people`.
      # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
      # @yieldparam person [Ecoportal::API::V1::Person] the **new** person.
      # @return [Eco::API::Organization::People] the starters.
      def with_each_starter(entries, people, options, log_present: false)
        starters = []
        micro.with_each(entries, people, options) do |entry, person|
          if !person.new? && log_present
            session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
            next
          end
          starters << person
          yield(entry, person) if block_given?
        end
        people.newFrom starters
      end

    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
eco-helpers-2.0.18 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.17 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.16 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.15 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.14 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.13 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.12 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.11 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.10 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.9 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.8 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.7 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.6 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.5 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.4 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.3 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-2.0.2 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-1.5.15 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-1.5.14 lib/eco/api/microcases/with_each_starter.rb
eco-helpers-1.5.13 lib/eco/api/microcases/with_each_starter.rb