Class: Eco::API::UseCases::DefaultCases::CreateDetailsCase

Inherits:
Common::Loaders::UseCase show all
Defined in:
lib/eco/api/usecases/backup/create_details_case.rb,
lib/eco/api/usecases/default_cases/create_details_case.rb

Instance Method Summary collapse

Methods inherited from Common::Loaders::UseCase

#initialize, type, #type

Methods inherited from Common::BaseLoader

<=>, created_at, #initialize, #name, name_only_once!, set_created_at!

Methods included from Common::ClassHelpers

#class_resolver, #descendants, #descendants?, #new_class, #resolve_class, #to_constant

Constructor Details

This class inherits a constructor from Eco::API::Common::Loaders::UseCase

Instance Method Details

#main(entries, people, session, options, usecase) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/eco/api/usecases/default_cases/create_details_case.rb', line 5

def main(entries, people, session, options, usecase)
  micro    = session.micro
  creation = session.new_job("main", "create",  :create, usecase)

  micro.with_each_starter(entries, people, options, log_present: true) do |entry, person|
    creation.add(person)
    micro.set_core(entry, person, options)
    entry.set_details(person) unless options.dig(:exclude, :details)
  end
end

#processObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/eco/api/usecases/backup/create_details_case.rb', line 7

def process
  @cases.define("create-details", type: :sync) do |entries, people, session, options, usecase|
    creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details])

    strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))

    entries.each.with_index do |entry, i|
      if person = people.find(entry, strict: strict_search)
        session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
      else
        person = session.new_person
        entry.set_core(person, exclude: "supervisor_id")
        entry.set_details(person)

        creation.add(person)
      end
    end
  end
end