global-registry-bindings 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/lib/global_registry_bindings/entity/entity_type_methods.rb +16 -18
  3. data/lib/global_registry_bindings/entity/mdm_methods.rb +11 -12
  4. data/lib/global_registry_bindings/entity/push_entity_methods.rb +23 -23
  5. data/lib/global_registry_bindings/entity/push_relationship_methods.rb +18 -18
  6. data/lib/global_registry_bindings/entity/relationship_type_methods.rb +26 -26
  7. data/lib/global_registry_bindings/exceptions.rb +7 -2
  8. data/lib/global_registry_bindings/global_registry_bindings.rb +19 -19
  9. data/lib/global_registry_bindings/model/delete_entity.rb +4 -4
  10. data/lib/global_registry_bindings/model/entity.rb +25 -25
  11. data/lib/global_registry_bindings/model/pull_mdm.rb +5 -5
  12. data/lib/global_registry_bindings/model/push_entity.rb +4 -4
  13. data/lib/global_registry_bindings/model/push_relationship.rb +10 -8
  14. data/lib/global_registry_bindings/model/relationship.rb +18 -18
  15. data/lib/global_registry_bindings/options/entity_class_options.rb +15 -15
  16. data/lib/global_registry_bindings/options/entity_instance_options.rb +11 -11
  17. data/lib/global_registry_bindings/options/entity_options_parser.rb +3 -3
  18. data/lib/global_registry_bindings/options/relationship_class_options.rb +22 -22
  19. data/lib/global_registry_bindings/options/relationship_instance_options.rb +12 -12
  20. data/lib/global_registry_bindings/options/relationship_options_parser.rb +7 -7
  21. data/lib/global_registry_bindings/options.rb +6 -6
  22. data/lib/global_registry_bindings/railtie.rb +7 -7
  23. data/lib/global_registry_bindings/testing.rb +3 -3
  24. data/lib/global_registry_bindings/version.rb +3 -3
  25. data/lib/global_registry_bindings/worker.rb +5 -5
  26. data/lib/global_registry_bindings/workers/delete_entity_worker.rb +3 -3
  27. data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +5 -5
  28. data/lib/global_registry_bindings/workers/push_entity_worker.rb +6 -6
  29. data/lib/global_registry_bindings/workers/push_relationship_worker.rb +6 -6
  30. data/lib/global_registry_bindings.rb +3 -3
  31. metadata +16 -156
  32. data/spec/acceptance/global_registry_bindings_spec.rb +0 -191
  33. data/spec/factories/factories.rb +0 -72
  34. data/spec/fixtures/get_entities_person.json +0 -8
  35. data/spec/fixtures/get_entities_person_mdm.json +0 -13
  36. data/spec/fixtures/get_entities_person_relationship.json +0 -32
  37. data/spec/fixtures/get_entity_types.json +0 -9
  38. data/spec/fixtures/get_entity_types_address.json +0 -59
  39. data/spec/fixtures/get_entity_types_address_partial.json +0 -43
  40. data/spec/fixtures/get_entity_types_area.json +0 -44
  41. data/spec/fixtures/get_entity_types_community.json +0 -18
  42. data/spec/fixtures/get_entity_types_fancy_org.json +0 -43
  43. data/spec/fixtures/get_entity_types_fancy_org_assignment.json +0 -35
  44. data/spec/fixtures/get_entity_types_fancy_org_partial.json +0 -35
  45. data/spec/fixtures/get_entity_types_ministry.json +0 -18
  46. data/spec/fixtures/get_entity_types_person.json +0 -42
  47. data/spec/fixtures/get_entity_types_person_partial.json +0 -34
  48. data/spec/fixtures/get_relationship_types.json +0 -9
  49. data/spec/fixtures/get_relationship_types_person_fancy_org.json +0 -41
  50. data/spec/fixtures/get_relationship_types_person_fancy_org_partial.json +0 -33
  51. data/spec/fixtures/post_entities_community.json +0 -8
  52. data/spec/fixtures/post_entities_fancy_org.json +0 -8
  53. data/spec/fixtures/post_entities_fancy_org_parent.json +0 -8
  54. data/spec/fixtures/post_entities_person.json +0 -8
  55. data/spec/fixtures/post_entity_types_address.json +0 -9
  56. data/spec/fixtures/post_entity_types_fancy_org.json +0 -9
  57. data/spec/fixtures/post_entity_types_person.json +0 -9
  58. data/spec/fixtures/post_relationship_types_assigned_by.json +0 -16
  59. data/spec/fixtures/post_relationship_types_community_ministry.json +0 -16
  60. data/spec/fixtures/post_relationship_types_fancy_org_area.json +0 -16
  61. data/spec/fixtures/post_relationship_types_person_fancy_org.json +0 -16
  62. data/spec/fixtures/put_entities_address.json +0 -20
  63. data/spec/fixtures/put_entities_community_relationship.json +0 -16
  64. data/spec/fixtures/put_entities_fancy_org_area_relationship.json +0 -8
  65. data/spec/fixtures/put_entities_fancy_org_assignment_assigned_by.json +0 -20
  66. data/spec/fixtures/put_entities_fancy_org_relationship.json +0 -17
  67. data/spec/fixtures/put_entities_person_country_relationship.json +0 -23
  68. data/spec/fixtures/put_entities_person_relationship.json +0 -29
  69. data/spec/fixtures/put_entities_relationship.json +0 -8
  70. data/spec/fixtures/put_entities_relationship_400.json +0 -3
  71. data/spec/fixtures/put_relationship_types_fields.json +0 -33
  72. data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +0 -25
  73. data/spec/helpers/sidekiq_helpers.rb +0 -14
  74. data/spec/internal/app/models/address.rb +0 -17
  75. data/spec/internal/app/models/application_record.rb +0 -5
  76. data/spec/internal/app/models/area.rb +0 -7
  77. data/spec/internal/app/models/assignment.rb +0 -21
  78. data/spec/internal/app/models/community.rb +0 -20
  79. data/spec/internal/app/models/country.rb +0 -8
  80. data/spec/internal/app/models/default.rb +0 -6
  81. data/spec/internal/app/models/namespaced/person/user_edited.rb +0 -8
  82. data/spec/internal/app/models/namespaced/person.rb +0 -68
  83. data/spec/internal/app/models/organization.rb +0 -37
  84. data/spec/internal/config/database.yml +0 -4
  85. data/spec/internal/config/initializers/global_registry.rb +0 -8
  86. data/spec/internal/config/routes.rb +0 -5
  87. data/spec/internal/db/schema.rb +0 -75
  88. data/spec/internal/db/test.sqlite +0 -0
  89. data/spec/internal/log/test.log +0 -1457
  90. data/spec/models/address_spec.rb +0 -30
  91. data/spec/models/assignment_spec.rb +0 -54
  92. data/spec/models/organization_spec.rb +0 -125
  93. data/spec/models/person_spec.rb +0 -191
  94. data/spec/models/testing_spec.rb +0 -55
  95. data/spec/models/user_edited_person_spec.rb +0 -14
  96. data/spec/options/if_unless_spec.rb +0 -147
  97. data/spec/spec_helper.rb +0 -52
  98. data/spec/workers/delete_gr_entity_worker_spec.rb +0 -33
  99. data/spec/workers/pull_mdm_id_worker_spec.rb +0 -133
  100. data/spec/workers/push_entity_worker_spec.rb +0 -506
  101. data/spec/workers/push_relationship_worker_spec.rb +0 -503
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0847a25784209dfd574ace31c1162e14759f3bcd993a19ad010444011da4b4b2'
4
- data.tar.gz: ad25738f695ef03adf447d56e3d7f326995f415cab23776b922aece4bd74dfa7
3
+ metadata.gz: 3e4acb61aa233cff5f2948d77c78a90e208c29cf0a1e88e1335749beec9c5059
4
+ data.tar.gz: 3e013e74ff1c6afe972cbe49983a72a50c04433ebd21533aa29865a6eba4ae34
5
5
  SHA512:
6
- metadata.gz: 61bac2dee0d7605aa729e370fcd4631d16064388eecf99cf6f91a36e1fc10663a218ac50df286bd195520308524d0e70200334edccd9ec9ba02bce589ab4e556
7
- data.tar.gz: b1e02c355122d43651651da8cf0c1c904ab004052f4022b006270594b5e259a5a9b40910a0a43a091f0d020a78daaa176b0629dee43bfc33f7a5ce242e950c63
6
+ metadata.gz: a0c2cb36c94004bd09186cb8ce24344826b0dfdf54f89fed7fc639c8b2fac7fc6f14942bb52a0ac35d89c8ad574d67eba32a215197d1d59bd0b69df498c68e8b
7
+ data.tar.gz: d74b7b86153c1a2024d4bd2cf3457ac907a4cc392b45e7a2c4d860fd06e6342ee4cffbf21f2ae88944ac8c10b269db5fd52596fe963490fadd19398b5233e3b6
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'global_registry'
3
+ require "global_registry"
4
4
 
5
- module GlobalRegistry #:nodoc:
6
- module Bindings #:nodoc:
7
- module Entity #:nodoc:
5
+ module GlobalRegistry # :nodoc:
6
+ module Bindings # :nodoc:
7
+ module Entity # :nodoc:
8
8
  module EntityTypeMethods
9
9
  extend ActiveSupport::Concern
10
10
 
@@ -12,15 +12,13 @@ module GlobalRegistry #:nodoc:
12
12
  return unless global_registry_entity.ensure_type?
13
13
  parent_entity_id = parent_entity_type_id
14
14
  entity_type = Rails.cache.fetch(entity_type_cache_key, expires_in: 1.hour) do
15
- GlobalRegistry::EntityType.get('filters[name]' => global_registry_entity.type,
16
- 'filters[parent_id]' => parent_entity_id)['entity_types']&.first
15
+ GlobalRegistry::EntityType.get("filters[name]" => global_registry_entity.type,
16
+ "filters[parent_id]" => parent_entity_id)["entity_types"]&.first
17
17
  end
18
18
 
19
- unless entity_type
20
- entity_type = GlobalRegistry::EntityType.post(entity_type: { name: global_registry_entity.type,
21
- parent_id: parent_entity_id,
22
- field_type: 'entity' })['entity_type']
23
- end
19
+ entity_type ||= GlobalRegistry::EntityType.post(entity_type: {name: global_registry_entity.type,
20
+ parent_id: parent_entity_id,
21
+ field_type: "entity"})["entity_type"]
24
22
 
25
23
  push_entity_type_fields_to_global_registry(entity_type)
26
24
  entity_type
@@ -29,13 +27,13 @@ module GlobalRegistry #:nodoc:
29
27
  private
30
28
 
31
29
  def push_entity_type_fields_to_global_registry(entity_type)
32
- existing_fields = entity_type['fields']&.collect { |f| f['name'].to_sym } || []
30
+ existing_fields = entity_type["fields"]&.collect { |f| f["name"].to_sym } || []
33
31
  model.entity_columns_to_push
34
- .reject { |k, _v| existing_fields.include? k }
35
- .each do |name, type|
36
- GlobalRegistry::EntityType.post(entity_type: { name: name,
37
- parent_id: entity_type['id'],
38
- field_type: type })
32
+ .except(*existing_fields)
33
+ .each do |name, type|
34
+ GlobalRegistry::EntityType.post(entity_type: {name: name,
35
+ parent_id: entity_type["id"],
36
+ field_type: type})
39
37
  end
40
38
  end
41
39
 
@@ -44,7 +42,7 @@ module GlobalRegistry #:nodoc:
44
42
  return if parent.blank? || global_registry_entity.parent_is_self?
45
43
  worker = GlobalRegistry::Bindings::Workers::PushEntityWorker.new parent
46
44
  parent_entity_type = worker.send :push_entity_type_to_global_registry
47
- parent_entity_type&.dig('id')
45
+ parent_entity_type&.dig("id")
48
46
  end
49
47
 
50
48
  def entity_type_cache_key
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GlobalRegistry #:nodoc:
4
- module Bindings #:nodoc:
5
- module Entity #:nodoc:
3
+ module GlobalRegistry # :nodoc:
4
+ module Bindings # :nodoc:
5
+ module Entity # :nodoc:
6
6
  module MdmMethods
7
7
  extend ActiveSupport::Concern
8
8
 
@@ -11,23 +11,22 @@ module GlobalRegistry #:nodoc:
11
11
  # Record missing Global Registry ID, enqueue it to be pushed.
12
12
  model.push_entity_to_global_registry_async
13
13
  raise GlobalRegistry::Bindings::RecordMissingGlobalRegistryId,
14
- "#{model.class.name}(#{model.id}) has no #{global_registry_entity.id_column}; will retry"
14
+ "#{model.class.name}(#{model.id}) has no #{global_registry_entity.id_column}; will retry"
15
15
  end
16
- entity = GlobalRegistry::Entity.find(global_registry_entity.id_value, 'filters[owned_by]' => 'mdm')
16
+ entity = GlobalRegistry::Entity.find(global_registry_entity.id_value, "filters[owned_by]" => "mdm")
17
17
  mdm_entity_id = dig_global_registry_mdm_id_from_entity(entity, global_registry_entity.type.to_s)
18
18
  unless mdm_entity_id
19
19
  raise GlobalRegistry::Bindings::EntityMissingMdmId,
20
- "GR entity #{global_registry_entity.id_value} for #{model.class.name}(#{model.id}) has no mdm id; " \
21
- 'will retry'
20
+ "GR entity #{global_registry_entity.id_value} for #{model.class.name}(#{model.id}) has no mdm id; " \
21
+ "will retry"
22
22
  end
23
- # rubocop:disable Rails/SkipsModelValidations
24
- model.update_column(global_registry_entity.mdm_id_column, mdm_entity_id)
23
+ model.update_column(global_registry_entity.mdm_id_column, mdm_entity_id) # rubocop:disable Rails/SkipsModelValidations
25
24
  end
26
25
 
27
26
  def dig_global_registry_mdm_id_from_entity(entity, type)
28
- Array.wrap(entity.dig('entity', type, "master_#{type}:relationship"))
29
- .first # although there should not be more than one
30
- .try(:[], "master_#{type}")
27
+ Array.wrap(entity.dig("entity", type, "master_#{type}:relationship"))
28
+ .first # although there should not be more than one
29
+ .try(:[], "master_#{type}")
31
30
  end
32
31
  end
33
32
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'deepsort'
4
- require 'digest/md5'
3
+ require "deepsort"
4
+ require "digest/md5"
5
5
 
6
- module GlobalRegistry #:nodoc:
7
- module Bindings #:nodoc:
8
- module Entity #:nodoc:
6
+ module GlobalRegistry # :nodoc:
7
+ module Bindings # :nodoc:
8
+ module Entity # :nodoc:
9
9
  module PushEntityMethods
10
10
  extend ActiveSupport::Concern
11
11
 
@@ -25,7 +25,7 @@ module GlobalRegistry #:nodoc:
25
25
  end
26
26
 
27
27
  def update_entity_in_global_registry
28
- entity_attributes = { global_registry_entity.type => model.entity_attributes_to_push }
28
+ entity_attributes = {global_registry_entity.type => model.entity_attributes_to_push}
29
29
  GlobalRegistry::Entity.put(global_registry_entity.id_value, entity: entity_attributes)
30
30
  update_fingerprint
31
31
  rescue RestClient::ResourceNotFound
@@ -35,12 +35,12 @@ module GlobalRegistry #:nodoc:
35
35
 
36
36
  def create_entity_in_global_registry
37
37
  ensure_parent_entity_has_global_registry_id! if global_registry_entity.parent.present?
38
- entity_attributes = { global_registry_entity.type => model.entity_attributes_to_push }
38
+ entity_attributes = {global_registry_entity.type => model.entity_attributes_to_push}
39
39
  entity = GlobalRegistry::Entity.post(entity: entity_attributes)
40
- global_registry_entity.id_value = dig_global_registry_id_from_entity(entity['entity'],
41
- global_registry_entity.type)
40
+ global_registry_entity.id_value = dig_global_registry_id_from_entity(entity["entity"],
41
+ global_registry_entity.type)
42
42
  model.update_column(global_registry_entity.id_column, # rubocop:disable Rails/SkipsModelValidations
43
- global_registry_entity.id_value)
43
+ global_registry_entity.id_value)
44
44
  update_fingerprint
45
45
  end
46
46
 
@@ -50,35 +50,35 @@ module GlobalRegistry #:nodoc:
50
50
  ensure_parent_entity_has_global_registry_id!
51
51
  entity_attributes = {
52
52
  global_registry_entity.parent_type => {
53
- client_integration_id: global_registry_entity.parent.id,
53
+ :client_integration_id => global_registry_entity.parent.id,
54
54
  global_registry_entity.type => model.entity_attributes_to_push
55
55
  }
56
56
  }
57
57
  entity = GlobalRegistry::Entity.put(global_registry_entity.parent_id_value, entity: entity_attributes)
58
- global_registry_entity.id_value = dig_global_registry_id_from_entity(entity['entity'],
59
- global_registry_entity.type,
60
- global_registry_entity.parent_type)
58
+ global_registry_entity.id_value = dig_global_registry_id_from_entity(entity["entity"],
59
+ global_registry_entity.type,
60
+ global_registry_entity.parent_type)
61
61
  model.update_column(global_registry_entity.id_column, # rubocop:disable Rails/SkipsModelValidations
62
- global_registry_entity.id_value)
62
+ global_registry_entity.id_value)
63
63
  update_fingerprint
64
64
  end
65
65
 
66
66
  def dig_global_registry_id_from_entity(entity, type, parent_type = nil)
67
- return entity&.dig(type.to_s, 'id') unless parent_type
67
+ return entity&.dig(type.to_s, "id") unless parent_type
68
68
  Array.wrap(entity&.dig(parent_type.to_s, type.to_s)).detect do |item|
69
- item['client_integration_id'] == model.id.to_s
70
- end&.dig('id')
69
+ item["client_integration_id"] == model.id.to_s
70
+ end&.dig("id")
71
71
  end
72
72
 
73
73
  def ensure_parent_entity_has_global_registry_id!
74
74
  return unless (global_registry_entity.parent_is_self? && global_registry_entity.parent_id_value.blank?) ||
75
- global_registry_entity.parent_id_value.blank?
75
+ global_registry_entity.parent_id_value.blank?
76
76
  # Push parent entity if it exists and is missing global_registry_id
77
77
  global_registry_entity.parent.push_entity_to_global_registry_async
78
78
  raise GlobalRegistry::Bindings::ParentEntityMissingGlobalRegistryId,
79
- "#{model.class.name}(#{model.id}) has parent entity " \
80
- "#{global_registry_entity.parent.class.name}(#{global_registry_entity.parent.id}) missing " \
81
- 'global_registry_id; will retry.'
79
+ "#{model.class.name}(#{model.id}) has parent entity " \
80
+ "#{global_registry_entity.parent.class.name}(#{global_registry_entity.parent.id}) missing " \
81
+ "global_registry_id; will retry."
82
82
  end
83
83
 
84
84
  def entity_fingerprint
@@ -89,7 +89,7 @@ module GlobalRegistry #:nodoc:
89
89
  def update_fingerprint
90
90
  return if global_registry_entity.fingerprint_column.blank?
91
91
  model.update_column(global_registry_entity.fingerprint_column, # rubocop:disable Rails/SkipsModelValidations
92
- entity_fingerprint)
92
+ entity_fingerprint)
93
93
  end
94
94
 
95
95
  def fingerprints_match?
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'global_registry'
4
- require 'global_registry_bindings/workers/delete_entity_worker'
3
+ require "global_registry"
4
+ require "global_registry_bindings/workers/delete_entity_worker"
5
5
 
6
- module GlobalRegistry #:nodoc:
7
- module Bindings #:nodoc:
8
- module Entity #:nodoc:
6
+ module GlobalRegistry # :nodoc:
7
+ module Bindings # :nodoc:
8
+ module Entity # :nodoc:
9
9
  module PushRelationshipMethods
10
10
  extend ActiveSupport::Concern
11
11
 
@@ -46,15 +46,15 @@ module GlobalRegistry #:nodoc:
46
46
 
47
47
  def global_registry_relationship_entity_id_from_entity(entity)
48
48
  relationships = Array.wrap entity.dig(
49
- 'entity',
49
+ "entity",
50
50
  relationship.primary_type.to_s,
51
51
  "#{relationship.related_name}:relationship"
52
52
  )
53
53
  relationships.detect do |rel|
54
- cid = rel['client_integration_id']
55
- cid = cid['value'] if cid.is_a?(Hash)
54
+ cid = rel["client_integration_id"]
55
+ cid = cid["value"] if cid.is_a?(Hash)
56
56
  cid == relationship.client_integration_id.to_s
57
- end&.dig('relationship_entity_id')
57
+ end&.dig("relationship_entity_id")
58
58
  end
59
59
 
60
60
  def ensure_related_entities_have_global_registry_ids!
@@ -68,8 +68,8 @@ module GlobalRegistry #:nodoc:
68
68
  names << push_related_to_global_registry
69
69
  end
70
70
  raise GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId,
71
- "#{model.class.name}(#{model.id}) has related entities [#{names.compact.join ', '}] missing " \
72
- 'global_registry_id; will retry.'
71
+ "#{model.class.name}(#{model.id}) has related entities [#{names.compact.join ", "}] missing " \
72
+ "global_registry_id; will retry."
73
73
  end
74
74
 
75
75
  def push_primary_to_global_registry
@@ -89,12 +89,12 @@ module GlobalRegistry #:nodoc:
89
89
  end
90
90
 
91
91
  def relationship_entity
92
- { entity: { relationship.primary_type => {
92
+ {entity: {relationship.primary_type => {
93
93
  "#{relationship.related_name}:relationship" =>
94
94
  model.relationship_attributes_to_push(type)
95
- .merge(relationship.related_type =>
95
+ .merge(relationship.related_type =>
96
96
  relationship.related_id_value)
97
- }, client_integration_id: relationship.primary.id } }
97
+ }, :client_integration_id => relationship.primary.id}}
98
98
  end
99
99
 
100
100
  def put_relationship_to_global_registry
@@ -108,7 +108,7 @@ module GlobalRegistry #:nodoc:
108
108
  )
109
109
  rescue RestClient::BadRequest => e
110
110
  response = JSON.parse(e.response.body)
111
- raise unless response['error'] =~ /^Validation failed:.*already exists$/i
111
+ raise unless /^Validation failed:.*already exists$/i.match?(response["error"])
112
112
  # Delete relationship entity and retry on 400 Bad Request (client_integration_id already exists)
113
113
  delete_relationship_from_global_registry
114
114
  end
@@ -120,9 +120,9 @@ module GlobalRegistry #:nodoc:
120
120
  )
121
121
  return unless and_retry
122
122
  raise GlobalRegistry::Bindings::RelatedEntityExistsWithCID,
123
- "#{model.class.name}(#{model.id}) #{relationship.related_name}" \
124
- ':relationship already exists with client_integration_id(' \
125
- "#{relationship.client_integration_id}). Will delete and retry."
123
+ "#{model.class.name}(#{model.id}) #{relationship.related_name}" \
124
+ ":relationship already exists with client_integration_id(" \
125
+ "#{relationship.client_integration_id}). Will delete and retry."
126
126
  end
127
127
  end
128
128
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'global_registry'
3
+ require "global_registry"
4
4
 
5
- module GlobalRegistry #:nodoc:
6
- module Bindings #:nodoc:
7
- module Entity #:nodoc:
5
+ module GlobalRegistry # :nodoc:
6
+ module Bindings # :nodoc:
7
+ module Entity # :nodoc:
8
8
  module RelationshipTypeMethods
9
9
  extend ActiveSupport::Concern
10
10
 
@@ -17,9 +17,9 @@ module GlobalRegistry #:nodoc:
17
17
 
18
18
  relationship_type = Rails.cache.fetch(relationship_type_cache_key, expires_in: 1.hour) do
19
19
  rel = GlobalRegistry::RelationshipType.get(
20
- 'filters[between]' => "#{primary_entity_type_id},#{related_entity_type_id}"
21
- )['relationship_types'].detect do |r|
22
- r['relationship1']['relationship_name'] ==
20
+ "filters[between]" => "#{primary_entity_type_id},#{related_entity_type_id}"
21
+ )["relationship_types"].detect do |r|
22
+ r["relationship1"]["relationship_name"] ==
23
23
  global_registry_relationship(type).primary_name.to_s
24
24
  end
25
25
  unless rel
@@ -30,7 +30,7 @@ module GlobalRegistry #:nodoc:
30
30
  relationship1: global_registry_relationship(type).primary_name,
31
31
  relationship2: global_registry_relationship(type).related_name
32
32
  }
33
- )['relationship_type']
33
+ )["relationship_type"]
34
34
  rename_relationship_entity_type(rel)
35
35
  end
36
36
  rel
@@ -48,10 +48,10 @@ module GlobalRegistry #:nodoc:
48
48
  unless entity_type
49
49
  primary_type = global_registry_relationship(type).primary_type
50
50
  entity_type = GlobalRegistry::EntityType.get(
51
- 'filters[name]' => primary_type
52
- )['entity_types']&.first
51
+ "filters[name]" => primary_type
52
+ )["entity_types"]&.first
53
53
  end
54
- entity_type&.dig('id')
54
+ entity_type&.dig("id")
55
55
  end
56
56
 
57
57
  def related_associated_entity_type_id
@@ -59,37 +59,37 @@ module GlobalRegistry #:nodoc:
59
59
  related_type = global_registry_relationship(type).related_type
60
60
  # remote foreign_key doesn't have a model class in rails. Short-circuit and fetch entity_type by name
61
61
  entity_type = GlobalRegistry::EntityType.get(
62
- 'filters[name]' => related_type
63
- )['entity_types']&.first
62
+ "filters[name]" => related_type
63
+ )["entity_types"]&.first
64
64
  unless entity_type
65
65
  raise GlobalRegistry::Bindings::RelatedEntityTypeMissing,
66
- "#{model.class.name}(#{model.id}) has unknown related entity_type(#{related_type}) in " \
67
- 'global_registry. Entity Type must exist in Global Registry for remote foreign_key relationship.'
66
+ "#{model.class.name}(#{model.id}) has unknown related entity_type(#{related_type}) in " \
67
+ "global_registry. Entity Type must exist in Global Registry for remote foreign_key relationship."
68
68
  end
69
- return entity_type&.dig('id')
69
+ return entity_type&.dig("id")
70
70
  end
71
71
  related_worker =
72
72
  GlobalRegistry::Bindings::Workers::PushEntityWorker.new global_registry_relationship(type).related
73
- related_worker.send(:push_entity_type_to_global_registry)&.dig('id')
73
+ related_worker.send(:push_entity_type_to_global_registry)&.dig("id")
74
74
  end
75
75
 
76
76
  def push_global_registry_relationship_type_fields(relationship_type)
77
- existing_fields = relationship_type['fields']&.collect { |f| f['name'].to_sym } || []
77
+ existing_fields = relationship_type["fields"]&.collect { |f| f["name"].to_sym } || []
78
78
  fields = model.relationship_columns_to_push(type)
79
- .reject { |k, _v| existing_fields.include? k }
80
- .map { |name, type| { name: name, field_type: type } }
79
+ .except(*existing_fields)
80
+ .map { |name, type| {name: name, field_type: type} }
81
81
  return if fields.empty?
82
- relationship_type = GlobalRegistry::RelationshipType.put(relationship_type['id'],
83
- relationship_type: { fields: fields })
84
- &.dig('relationship_type')
82
+ relationship_type = GlobalRegistry::RelationshipType.put(relationship_type["id"],
83
+ relationship_type: {fields: fields})
84
+ &.dig("relationship_type")
85
85
  Rails.cache.write(relationship_type_cache_key, relationship_type, expires_in: 1.hour) if relationship_type
86
86
  end
87
87
 
88
88
  def rename_relationship_entity_type(relationship_type)
89
89
  return unless global_registry_relationship(type).rename_entity_type?
90
- entity_type_id = relationship_type&.dig('relationship_entity_type_id')
91
- GlobalRegistry::EntityType.put(entity_type_id, entity_type: { id: entity_type_id,
92
- name: global_registry_relationship(type).type })
90
+ entity_type_id = relationship_type&.dig("relationship_entity_type_id")
91
+ GlobalRegistry::EntityType.put(entity_type_id, entity_type: {id: entity_type_id,
92
+ name: global_registry_relationship(type).type})
93
93
  end
94
94
 
95
95
  def relationship_type_cache_key
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GlobalRegistry #:nodoc:
4
- module Bindings #:nodoc:
3
+ module GlobalRegistry # :nodoc:
4
+ module Bindings # :nodoc:
5
5
  class RecordMissingGlobalRegistryId < StandardError; end
6
+
6
7
  class EntityMissingMdmId < StandardError; end
8
+
7
9
  class RelatedEntityMissingGlobalRegistryId < StandardError; end
10
+
8
11
  class ParentEntityMissingGlobalRegistryId < StandardError; end
12
+
9
13
  class RelatedEntityExistsWithCID < StandardError; end
14
+
10
15
  class RelatedEntityTypeMissing < StandardError; end
11
16
  end
12
17
  end
@@ -1,33 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext'
4
- require 'global_registry'
5
- require 'global_registry_bindings/exceptions'
6
- require 'global_registry_bindings/options'
7
- require 'global_registry_bindings/options/entity_options_parser'
8
- require 'global_registry_bindings/options/relationship_options_parser'
9
- require 'global_registry_bindings/model/entity'
10
- require 'global_registry_bindings/model/push_entity'
11
- require 'global_registry_bindings/model/push_relationship'
12
- require 'global_registry_bindings/model/delete_entity'
13
- require 'global_registry_bindings/model/pull_mdm'
14
- require 'global_registry_bindings/model/relationship'
15
- require 'global_registry_bindings/worker'
3
+ require "active_support/core_ext"
4
+ require "global_registry"
5
+ require "global_registry_bindings/exceptions"
6
+ require "global_registry_bindings/options"
7
+ require "global_registry_bindings/options/entity_options_parser"
8
+ require "global_registry_bindings/options/relationship_options_parser"
9
+ require "global_registry_bindings/model/entity"
10
+ require "global_registry_bindings/model/push_entity"
11
+ require "global_registry_bindings/model/push_relationship"
12
+ require "global_registry_bindings/model/delete_entity"
13
+ require "global_registry_bindings/model/pull_mdm"
14
+ require "global_registry_bindings/model/relationship"
15
+ require "global_registry_bindings/worker"
16
16
 
17
- module GlobalRegistry #:nodoc:
18
- module Bindings #:nodoc:
17
+ module GlobalRegistry # :nodoc:
18
+ module Bindings # :nodoc:
19
19
  def global_registry_bindings(options = {})
20
20
  options[:binding] ||= :entity
21
21
  unless method_defined? :_global_registry_bindings_options
22
22
  class_attribute :_global_registry_bindings_options
23
- self._global_registry_bindings_options = { entity: nil, relationships: {} }
23
+ self._global_registry_bindings_options = {entity: nil, relationships: {}}
24
24
  end
25
25
  if options[:binding] == :entity
26
26
  global_registry_bindings_entity options
27
27
  elsif options[:binding] == :relationship
28
28
  global_registry_bindings_relationship options
29
29
  else
30
- raise ArgumentError, ':binding option must be :entity or :relationship'
30
+ raise ArgumentError, ":binding option must be :entity or :relationship"
31
31
  end
32
32
  end
33
33
 
@@ -35,10 +35,10 @@ module GlobalRegistry #:nodoc:
35
35
 
36
36
  def global_registry_bindings_entity(options = {})
37
37
  if _global_registry_bindings_options[:entity].present?
38
- raise '#global_registry_bindings with :entity binding called more than once.'
38
+ raise "#global_registry_bindings with :entity binding called more than once."
39
39
  end
40
40
  _global_registry_bindings_options[:entity] = GlobalRegistry::Bindings::Options::EntityOptionsParser.new(self)
41
- .parse(options)
41
+ .parse(options)
42
42
  include Options unless respond_to? :global_registry_entity
43
43
  global_registry_bindings_entity_includes
44
44
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'global_registry_bindings/workers/delete_entity_worker'
3
+ require "global_registry_bindings/workers/delete_entity_worker"
4
4
 
5
- module GlobalRegistry #:nodoc:
6
- module Bindings #:nodoc:
7
- module Model #:nodoc:
5
+ module GlobalRegistry # :nodoc:
6
+ module Bindings # :nodoc:
7
+ module Model # :nodoc:
8
8
  module DeleteEntity
9
9
  extend ActiveSupport::Concern
10
10
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GlobalRegistry #:nodoc:
4
- module Bindings #:nodoc:
5
- module Model #:nodoc:
3
+ module GlobalRegistry # :nodoc:
4
+ module Bindings # :nodoc:
5
+ module Model # :nodoc:
6
6
  module Entity
7
7
  extend ActiveSupport::Concern
8
8
 
@@ -11,7 +11,7 @@ module GlobalRegistry #:nodoc:
11
11
  value_for_global_registry(name, type)
12
12
  end.compact.to_h
13
13
  entity_attributes[:client_integration_id] = id unless global_registry_entity.exclude
14
- .include?(:client_integration_id)
14
+ .include?(:client_integration_id)
15
15
  if respond_to?(:updated_at) && updated_at.present?
16
16
  entity_attributes[:client_updated_at] = updated_at.to_s(:db)
17
17
  end
@@ -25,13 +25,13 @@ module GlobalRegistry #:nodoc:
25
25
  value = send(name)
26
26
  return [name, value] if value.nil?
27
27
  value = case type
28
- when :datetime, :date
29
- value.to_s(:db)
30
- when :boolean
31
- value ? 'true' : 'false'
32
- else
33
- value.to_s.strip
34
- end
28
+ when :datetime, :date
29
+ value.to_s(:db)
30
+ when :boolean
31
+ value ? "true" : "false"
32
+ else
33
+ value.to_s.strip
34
+ end
35
35
  [name, value]
36
36
  rescue ::NoMethodError
37
37
  nil
@@ -39,26 +39,26 @@ module GlobalRegistry #:nodoc:
39
39
 
40
40
  def entity_columns_to_push
41
41
  @columns_to_push ||= if global_registry_entity.include_all_columns?
42
- self
43
- .class
44
- .columns
45
- .collect do |c|
46
- { c.name.underscore.to_sym => normalize_entity_column_type(c.type, c.name) }
47
- end # rubocop:disable Style/MultilineBlockChain
48
- .reduce(&:merge)
49
- .reject { |k, _v| global_registry_entity.exclude.include? k }
50
- .merge(global_registry_entity.fields)
51
- else
52
- global_registry_entity.fields
53
- end
42
+ self
43
+ .class
44
+ .columns
45
+ .collect do |c|
46
+ {c.name.underscore.to_sym => normalize_entity_column_type(c.type, c.name)}
47
+ end # rubocop:disable Style/MultilineBlockChain
48
+ .reduce(&:merge)
49
+ .except(*global_registry_entity.exclude)
50
+ .merge(global_registry_entity.fields)
51
+ else
52
+ global_registry_entity.fields
53
+ end
54
54
  end
55
55
 
56
56
  protected
57
57
 
58
58
  def normalize_entity_column_type(type, name)
59
- if type.to_s == 'text'
59
+ if type.to_s == "text"
60
60
  :string
61
- elsif name.ends_with?('_id')
61
+ elsif name.ends_with?("_id")
62
62
  :uuid
63
63
  else
64
64
  type
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'global_registry_bindings/workers/pull_mdm_id_worker'
3
+ require "global_registry_bindings/workers/pull_mdm_id_worker"
4
4
 
5
- module GlobalRegistry #:nodoc:
6
- module Bindings #:nodoc:
7
- module Model #:nodoc:
5
+ module GlobalRegistry # :nodoc:
6
+ module Bindings # :nodoc:
7
+ module Model # :nodoc:
8
8
  module PullMdm
9
9
  extend ActiveSupport::Concern
10
10
 
@@ -17,7 +17,7 @@ module GlobalRegistry #:nodoc:
17
17
  return if global_registry_entity.condition?(:if)
18
18
  return unless global_registry_entity.condition?(:unless)
19
19
  "::GlobalRegistry::Bindings::Workers::#{global_registry_entity.mdm_worker_class_name}"
20
- .constantize .perform_async(self.class.name, id)
20
+ .constantize.perform_async(self.class.name, id)
21
21
  end
22
22
  end
23
23
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'global_registry_bindings/workers/push_entity_worker'
3
+ require "global_registry_bindings/workers/push_entity_worker"
4
4
 
5
- module GlobalRegistry #:nodoc:
6
- module Bindings #:nodoc:
7
- module Model #:nodoc:
5
+ module GlobalRegistry # :nodoc:
6
+ module Bindings # :nodoc:
7
+ module Model # :nodoc:
8
8
  module PushEntity
9
9
  extend ActiveSupport::Concern
10
10