Class: Eco::API::UseCases::DefaultCases::RestoreDBCase

Inherits:
Common::Loaders::UseCase show all
Defined in:
lib/eco/api/usecases/default_cases/restore_db_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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/eco/api/usecases/default_cases/restore_db_case.rb', line 5

def main(entries, people, session, options, usecase)
  micro    = session.micro
  require_people_as_entries!(entries)

  restart  = session.new_job("main", "restart", :create, usecase) if options.dig(:include, :create)
  update   = session.new_job("main", "update",  :update, usecase)
  delete   = session.new_job("main", "delete",  :update, usecase)

  if options.dig(:include, :delete)
    micro.with_each_leaver(entries, people, options) do |person|
      delete.add(person)
    end
  end

  re_starters = []

  micro.with_each(entries, people, options) do |entry, person|
    if person.new? && !options.dig(:include, :create)
      re_starters.push(entry);
      next
    end

    person.new? ? restart.add(person) : update.add(person)

    core_copy(entry, person, options) unless options.dig(:exclude, :core)
    person.details = entry.details    unless options.dig(:exclude, :details)

    unless options.dig(:exclude, :account) || !entry.
      person. ||= {}
      (entry., person., options)
    end
  end

  report_re_starters(re_starters, session.logger)
end