Sha256: 9e3493d6dc4c7c78452ad7e6d2975698274a8fc9470efbaba7ddc5e3c5159f29
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
# frozen_string_literal: true require 'global_registry_bindings/workers/pull_mdm_id_worker' module GlobalRegistry #:nodoc: module Bindings #:nodoc: module Entity #:nodoc: module MdmMethods extend ActiveSupport::Concern included do GlobalRegistry::Bindings::Workers.mdm_worker_class(self) after_commit :pull_mdm_id_from_global_registry_async, on: %i[create update] end def pull_mdm_id_from_global_registry_async "::GlobalRegistry::Bindings::Workers::#{global_registry.mdm_worker_class_name}".constantize .perform_async(self.class, id) end def pull_mdm_id_from_global_registry # rubocop:disable Metrics/AbcSize unless global_registry.id_value? # Record missing Global Registry ID, enqueue it to be pushed. push_entity_to_global_registry_async raise GlobalRegistry::Bindings::RecordMissingGlobalRegistryId, "#{self.class.name} #{id} has no #{global_registry.id_column}; will retry" end entity = GlobalRegistry::Entity.find(global_registry.id_value, 'filters[owned_by]' => 'mdm') mdm_entity_id = dig_global_registry_mdm_id_from_entity(entity, global_registry.type.to_s) unless mdm_entity_id raise GlobalRegistry::Bindings::EntityMissingMdmId, "GR entity #{global_registry.id_value} for #{self.class.name} #{id} has no mdm id; will retry" end update_column(global_registry.mdm_id_column, mdm_entity_id) # rubocop:disable Rails/SkipsModelValidations end def dig_global_registry_mdm_id_from_entity(entity, type) Array.wrap(entity.dig('entity', type, "master_#{type}:relationship")) .first # although there should not be more than one .try(:[], "master_#{type}") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
global-registry-bindings-0.0.6 | lib/global_registry_bindings/entity/mdm_methods.rb |