Class: Eco::API::UseCases::DefaultCases::UpdateDetailsCase
- Inherits:
-
Common::Loaders::UseCase
- Object
- Common::BaseLoader
- Common::Loaders::UseCase
- Eco::API::UseCases::DefaultCases::UpdateDetailsCase
- Defined in:
- lib/eco/api/usecases/backup/update_details_case.rb,
lib/eco/api/usecases/default_cases/update_details_case.rb
Instance Method Summary collapse
Methods inherited from Common::Loaders::UseCase
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 |
# File 'lib/eco/api/usecases/default_cases/update_details_case.rb', line 5 def main(entries, people, session, , usecase) micro = session.micro update = session.new_job("main", "update", :update, usecase) supers = session.new_job("post", "supers", :update, usecase, :core) micro.with_each_present(entries, people, , log_starter: true) do |entry, person| update.add(person) micro.set_core_with_supervisor(entry, person, people, supers, ) entry.set_details(person) unless .dig(:exclude, :details) end end |
#process ⇒ Object
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/eco/api/usecases/backup/update_details_case.rb', line 7 def process @cases.define("update-details", type: :sync) do |entries, people, session, , usecase| job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details]) supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core) strict_search = session.config.people.strict_search? && (![:search]&.key?(:strict) || .dig(:search, :strict)) entries.each.with_index do |entry, i| if person = people.find(entry, strict: strict_search) unless .dig(:exclude, :core) core_attrs = ["name", "external_id", "email", "filter_tags"] core_excluded = core_attrs.map.select {|attr| .dig(:exclude, attr.to_sym)} core_excluded.push("supervisor_id") entry.set_core(person, exclude: core_excluded) unless .dig(:exclude, :core) if session.tagtree && !.dig(:exclude, :filter_tags) person. = session.tagtree.( initial: , final: person., preserve_custom: true, add_custom: true ) end end entry.set_details(person) job.add(person) # set supervisor unless .dig(:exclude, :core) || .dig(:exclude, :supervisor) if !(sup_id = entry.supervisor_id) person.supervisor_id = nil else if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id) person.supervisor_id = supervisor.id else # delay setting supervisor if does not exit supers.add(person) do |person| person.supervisor_id = sup_id end end end end else session.logger.error("This person does not exist: #{entry.to_s(:identify)}") end end end end |