Sha256: 2f2b2b1c9fd84d71c5b8352f0ddb3d9f2945be4100ba3a5dbf80396d1c6b38f7

Contents?: true

Size: 1.52 KB

Versions: 20

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module GlobalRegistry #:nodoc:
  module Bindings #:nodoc:
    module Entity #:nodoc:
      module MdmMethods
        extend ActiveSupport::Concern

        def pull_mdm_id_from_global_registry # rubocop:disable Metrics/AbcSize
          unless global_registry_entity.id_value?
            # Record missing Global Registry ID, enqueue it to be pushed.
            model.push_entity_to_global_registry_async
            raise GlobalRegistry::Bindings::RecordMissingGlobalRegistryId,
                  "#{model.class.name}(#{model.id}) has no #{global_registry_entity.id_column}; will retry"
          end
          entity = GlobalRegistry::Entity.find(global_registry_entity.id_value, 'filters[owned_by]' => 'mdm')
          mdm_entity_id = dig_global_registry_mdm_id_from_entity(entity, global_registry_entity.type.to_s)
          unless mdm_entity_id
            raise GlobalRegistry::Bindings::EntityMissingMdmId,
                  "GR entity #{global_registry_entity.id_value} for #{model.class.name}(#{model.id}) has no mdm id; " \
                  'will retry'
          end
          # rubocop:disable Rails/SkipsModelValidations
          model.update_column(global_registry_entity.mdm_id_column, mdm_entity_id)
        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

20 entries across 20 versions & 1 rubygems

Version Path
global-registry-bindings-0.6.2 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.6.1 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.6.0 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.5.0 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.4.0 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.3.3 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.3.2 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.3.1 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.3.0 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.2.0 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.9 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.8 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.7 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.6 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.5 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.4 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.3 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.2 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.1 lib/global_registry_bindings/entity/mdm_methods.rb
global-registry-bindings-0.1.0 lib/global_registry_bindings/entity/mdm_methods.rb