global-registry-bindings 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +79 -35
- data/lib/global_registry_bindings/entity/entity_type_methods.rb +35 -33
- data/lib/global_registry_bindings/entity/mdm_methods.rb +9 -19
- data/lib/global_registry_bindings/entity/push_entity_methods.rb +31 -38
- data/lib/global_registry_bindings/entity/push_relationship_methods.rb +61 -47
- data/lib/global_registry_bindings/entity/relationship_type_methods.rb +48 -37
- data/lib/global_registry_bindings/exceptions.rb +1 -0
- data/lib/global_registry_bindings/global_registry_bindings.rb +129 -46
- data/lib/global_registry_bindings/{entity/delete_entity_methods.rb → model/delete_entity.rb} +5 -5
- data/lib/global_registry_bindings/model/entity.rb +64 -0
- data/lib/global_registry_bindings/model/pull_mdm.rb +23 -0
- data/lib/global_registry_bindings/model/push_entity.rb +21 -0
- data/lib/global_registry_bindings/model/push_relationship.rb +79 -0
- data/lib/global_registry_bindings/model/relationship.rb +68 -0
- data/lib/global_registry_bindings/options.rb +26 -59
- data/lib/global_registry_bindings/options/entity_class_options.rb +34 -0
- data/lib/global_registry_bindings/options/entity_instance_options.rb +90 -0
- data/lib/global_registry_bindings/options/entity_options_parser.rb +76 -0
- data/lib/global_registry_bindings/options/relationship_class_options.rb +37 -0
- data/lib/global_registry_bindings/options/relationship_instance_options.rb +131 -0
- data/lib/global_registry_bindings/options/relationship_options_parser.rb +98 -0
- data/lib/global_registry_bindings/railtie.rb +2 -1
- data/lib/global_registry_bindings/version.rb +1 -1
- data/lib/global_registry_bindings/worker.rb +25 -0
- data/lib/global_registry_bindings/workers/{delete_gr_entity_worker.rb → delete_entity_worker.rb} +1 -6
- data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +12 -13
- data/lib/global_registry_bindings/workers/push_entity_worker.rb +24 -0
- data/lib/global_registry_bindings/workers/push_relationship_worker.rb +17 -7
- data/spec/acceptance/global_registry_bindings_spec.rb +50 -40
- data/spec/factories/factories.rb +24 -0
- data/spec/fixtures/get_entity_types_area.json +44 -0
- data/spec/fixtures/post_entities_community.json +8 -0
- data/spec/fixtures/post_relationship_types_fancy_org_area.json +16 -0
- data/spec/fixtures/put_entities_community_relationship.json +16 -0
- data/spec/fixtures/put_entities_fancy_org_area_relationship.json +8 -0
- data/spec/fixtures/put_entities_fancy_org_relationship.json +17 -0
- data/spec/fixtures/put_entities_person_country_relationship.json +23 -0
- data/spec/fixtures/put_entities_relationship_400.json +3 -0
- data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +25 -0
- data/spec/helpers/sidekiq_helpers.rb +14 -0
- data/spec/internal/app/models/address.rb +7 -2
- data/spec/internal/app/models/area.rb +7 -0
- data/spec/internal/app/models/assignment.rb +5 -4
- data/spec/internal/app/models/community.rb +19 -0
- data/spec/internal/app/models/country.rb +8 -0
- data/spec/internal/app/models/namespaced/person.rb +48 -2
- data/spec/internal/app/models/organization.rb +26 -3
- data/spec/internal/db/schema.rb +28 -0
- data/spec/internal/log/test.log +71023 -0
- data/spec/models/address_spec.rb +6 -204
- data/spec/models/assignment_spec.rb +40 -186
- data/spec/models/organization_spec.rb +106 -92
- data/spec/models/person_spec.rb +158 -214
- data/spec/models/user_edited_person_spec.rb +2 -2
- data/spec/spec_helper.rb +5 -6
- data/spec/workers/delete_gr_entity_worker_spec.rb +4 -4
- data/spec/workers/pull_mdm_id_worker_spec.rb +94 -32
- data/spec/workers/push_entity_worker_spec.rb +476 -0
- data/spec/workers/push_relationship_worker_spec.rb +344 -15
- metadata +45 -10
- data/lib/global_registry_bindings/entity/entity_methods.rb +0 -62
- data/lib/global_registry_bindings/options/class_options.rb +0 -62
- data/lib/global_registry_bindings/options/instance_options.rb +0 -63
- data/lib/global_registry_bindings/workers/push_gr_entity_worker.rb +0 -22
- data/spec/workers/push_gr_entity_worker_spec.rb +0 -27
@@ -8,50 +8,61 @@ module GlobalRegistry #:nodoc:
|
|
8
8
|
module RelationshipTypeMethods
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
GlobalRegistry::RelationshipType.get(
|
17
|
-
'filters[between]' => "#{parent_entity_type_id},#{related_entity_type_id}"
|
18
|
-
)['relationship_types'].detect do |r|
|
19
|
-
r['relationship1']['relationship_name'] == global_registry.parent_relationship_name.to_s
|
20
|
-
end
|
21
|
-
end
|
11
|
+
# rubocop:disable Metrics/MethodLength
|
12
|
+
# rubocop:disable Metrics/AbcSize
|
13
|
+
def push_global_registry_relationship_type
|
14
|
+
return unless global_registry_relationship(type).ensure_relationship_type?
|
15
|
+
primary_entity_type_id, related_entity_type_id = associated_entity_ids
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
relationship2: global_registry.related_relationship_name
|
30
|
-
})['relationship_type']
|
17
|
+
relationship_type = Rails.cache.fetch(relationship_type_cache_key, expires_in: 1.hour) do
|
18
|
+
GlobalRegistry::RelationshipType.get(
|
19
|
+
'filters[between]' => "#{primary_entity_type_id},#{related_entity_type_id}"
|
20
|
+
)['relationship_types'].detect do |r|
|
21
|
+
r['relationship1']['relationship_name'] ==
|
22
|
+
global_registry_relationship(type).primary_relationship_name.to_s
|
31
23
|
end
|
32
|
-
push_global_registry_relationship_type_fields(relationship_type)
|
33
|
-
relationship_type
|
34
24
|
end
|
35
25
|
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
unless relationship_type
|
27
|
+
relationship_type =
|
28
|
+
GlobalRegistry::RelationshipType.post(
|
29
|
+
relationship_type: {
|
30
|
+
entity_type1_id: primary_entity_type_id,
|
31
|
+
entity_type2_id: related_entity_type_id,
|
32
|
+
relationship1: global_registry_relationship(type).primary_relationship_name,
|
33
|
+
relationship2: global_registry_relationship(type).related_relationship_name
|
34
|
+
}
|
35
|
+
)['relationship_type']
|
39
36
|
end
|
37
|
+
push_global_registry_relationship_type_fields(relationship_type)
|
38
|
+
relationship_type
|
39
|
+
end
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
41
|
+
# rubocop:enable Metrics/AbcSize
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
43
|
+
def associated_entity_ids
|
44
|
+
primary_worker =
|
45
|
+
GlobalRegistry::Bindings::Workers::PushEntityWorker.new global_registry_relationship(type).primary
|
46
|
+
related_worker =
|
47
|
+
GlobalRegistry::Bindings::Workers::PushEntityWorker.new global_registry_relationship(type).related
|
48
|
+
[primary_worker.send(:push_entity_type_to_global_registry)&.dig('id'),
|
49
|
+
related_worker.send(:push_entity_type_to_global_registry)&.dig('id')]
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
def push_global_registry_relationship_type_fields(relationship_type)
|
53
|
+
existing_fields = relationship_type['fields']&.collect { |f| f['name'].to_sym } || []
|
54
|
+
fields = model.relationship_columns_to_push(type)
|
55
|
+
.reject { |k, _v| existing_fields.include? k }
|
56
|
+
.map { |name, type| { name: name, field_type: type } }
|
57
|
+
return if fields.empty?
|
58
|
+
GlobalRegistry::RelationshipType.put(relationship_type['id'],
|
59
|
+
relationship_type: { fields: fields })
|
60
|
+
end
|
61
|
+
|
62
|
+
def relationship_type_cache_key
|
63
|
+
"GlobalRegistry::Bindings::RelationshipType::#{global_registry_relationship(type).primary_type}::" \
|
64
|
+
"#{global_registry_relationship(type).related_type}::" \
|
65
|
+
"#{global_registry_relationship(type).primary_relationship_name}"
|
55
66
|
end
|
56
67
|
end
|
57
68
|
end
|
@@ -6,5 +6,6 @@ module GlobalRegistry #:nodoc:
|
|
6
6
|
class EntityMissingMdmId < StandardError; end
|
7
7
|
class RelatedEntityMissingGlobalRegistryId < StandardError; end
|
8
8
|
class ParentEntityMissingGlobalRegistryId < StandardError; end
|
9
|
+
class RelatedEntityExistsWithCID < StandardError; end
|
9
10
|
end
|
10
11
|
end
|
@@ -4,13 +4,15 @@ require 'active_support/core_ext'
|
|
4
4
|
require 'global_registry'
|
5
5
|
require 'global_registry_bindings/exceptions'
|
6
6
|
require 'global_registry_bindings/options'
|
7
|
-
require 'global_registry_bindings/
|
8
|
-
require 'global_registry_bindings/
|
9
|
-
require 'global_registry_bindings/entity
|
10
|
-
require 'global_registry_bindings/
|
11
|
-
require 'global_registry_bindings/
|
12
|
-
require 'global_registry_bindings/
|
13
|
-
require 'global_registry_bindings/
|
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'
|
14
16
|
|
15
17
|
module GlobalRegistry #:nodoc:
|
16
18
|
module Bindings #:nodoc:
|
@@ -18,59 +20,140 @@ module GlobalRegistry #:nodoc:
|
|
18
20
|
#
|
19
21
|
# Options:
|
20
22
|
#
|
21
|
-
# * `:
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
23
|
+
# * `:binding`: Type of Global Registry binding. Either `:entity` or `:relationship`.
|
24
|
+
# (default: `:entity`)
|
25
|
+
#
|
26
|
+
# * `:id_column`: Column used to track the Global Registry ID for the model instance or relationship entity.
|
27
|
+
# Can be a :string or :uuid column. (default: `:global_registry_id`) **[`:entity`, `:relationship`]**
|
28
|
+
#
|
29
|
+
# * `:type`: Global Registry entity type. Accepts a Symbol or a Proc. Symbol is the name of the entity type, Proc
|
30
|
+
# is passed the model instance and must return a symbol which is the entity type. Default value is underscored
|
31
|
+
# name of the model. Ex: ```type: proc { |model| model.name.to_sym }```. When used in a `:relationship`, `:type`
|
32
|
+
# is a unique name to identify the relationship. **[`:entity`, `:relationship`]**
|
33
|
+
#
|
26
34
|
# * `:push_on`: Array of Active Record lifecycle events used to push changes to Global Registry.
|
27
|
-
#
|
35
|
+
# (default: `[:create, :update, :destroy]`) **[`:entity`]**
|
36
|
+
#
|
28
37
|
# * `:parent_association`: Name of the Active Record parent association. Must be defined before calling
|
29
|
-
#
|
38
|
+
# global_registry_bindings in order to determine foreign_key for use in exclude_fields. Used to create a
|
39
|
+
# hierarchy or to push child entity types. (Ex: person -> address) (default: `nil`) **[`:entity`]**
|
40
|
+
#
|
30
41
|
# * `:parent_association_class`: Class name of the parent model. Required if `:parent_association` can not be used
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
42
|
+
# to determine the parent class. This can happen if parent is defined by another gem, like `ancestry`.
|
43
|
+
# (default: `nil`) **[`:entity`]**
|
44
|
+
#
|
45
|
+
# * `:primary_association`: Name of the Active Record primary association. Must be defined before calling
|
46
|
+
# global_registry_bindings in order to determine foreign_key for use in exclude_fields. (default: `nil`)
|
47
|
+
# **[`:relationship`]**
|
48
|
+
#
|
49
|
+
# * `:primary_association_class`: Class name of the primary model. Required if `:primary_association` can not be
|
50
|
+
# used to determine the parent class. This can happen if parent is defined by another gem, like `ancestry`.
|
51
|
+
# (default: `self.class`) **[`:relationship`]**
|
52
|
+
#
|
53
|
+
# * `:primary_association_foreign_key`: Foreign Key column for the primary association. Used if foreign_key can
|
54
|
+
# not be determined from `:primary_association`. (default: `:primary_association.foreign_key`)
|
55
|
+
# **[`:relationship`]**
|
56
|
+
#
|
57
|
+
# * `:related_association`: Name of the Active Record related association. Active Record association must be
|
58
|
+
# defined before calling global_registry_bindings in order to determine the foreign key.
|
59
|
+
# (default: `nil`) **[`:relationship`]**
|
60
|
+
#
|
37
61
|
# * `:related_association_class`: Class name of the related model. Required if `:related_association` can not be
|
38
|
-
# used to determine the related class. (default: `nil`)
|
39
|
-
#
|
40
|
-
# * `:
|
41
|
-
#
|
42
|
-
# `:
|
43
|
-
#
|
44
|
-
# * `:
|
45
|
-
#
|
46
|
-
#
|
62
|
+
# used to determine the related class. (default: `nil`) **[`:relationship`]**
|
63
|
+
#
|
64
|
+
# * `:related_association_foreign_key`: Foreign Key column for the related association. Used if foreign_key can
|
65
|
+
# not be determined from `:primary_association`. (default: `:primary_association.foreign_key`)
|
66
|
+
# **[`:relationship`]**
|
67
|
+
#
|
68
|
+
# * `:primary_relationship_name`: Name of primary relationship role. Required if `:ensure_relationship_type` is
|
69
|
+
# `true`. (default: `nil`) **[`:relationship`]**
|
70
|
+
#
|
71
|
+
# * `:related_relationship_name`: Name of the related relationship role. Required if `:ensure_relationship_type`
|
72
|
+
# is `true`. (default: `nil`) **[`:relationship`]**
|
73
|
+
#
|
74
|
+
# * `:related_association_type`: Name of the related association entity_type. Required if unable to determined
|
75
|
+
# `:type` from related. (default: `nil`) **[`:relationship`]**
|
76
|
+
#
|
77
|
+
# * `:related_global_registry_id`: Global Registry ID of a remote related entity. Proc or Symbol. Implementation
|
78
|
+
# should cache this as it may be requested multiple times. (default: `nil`) **[`:relationship`]**
|
79
|
+
#
|
80
|
+
# * `:ensure_relationship_type`: Ensure Global Registry RelationshipType exists and is up to date.
|
81
|
+
# (default: `true`) **[`:relationship`]**
|
82
|
+
#
|
83
|
+
# * `:ensure_entity_type`: Ensure Global Registry Entity Type exists and is up to date.
|
84
|
+
# (default: `true`) **[`:entity`]**
|
85
|
+
#
|
86
|
+
# * `:client_integration_id`: Client Integration ID for relationship. Proc or Symbol.
|
87
|
+
# (default: `:primary_association.id`) **[`:relationship`]**
|
88
|
+
#
|
89
|
+
# * `:exclude_fields`: Array, Proc or Symbol. Array of Model fields (as symbols) to exclude when pushing to Global
|
90
|
+
# Registry. Array Will additionally include `:mdm_id_column` and `:parent_association` foreign key when defined.
|
91
|
+
# If Proc, is passed type and model instance and should return an Array of the fields to exclude. If Symbol,
|
92
|
+
# this should be a method name the Model instance responds to. It is passed the type and should return an Array
|
93
|
+
# of fields to exclude. When Proc or Symbol are used, you must explicitly return the standard defaults.
|
94
|
+
# (default: `[:id, :created_at, :updated_at, :global_registry_id]`) **[`:entity`, `:relationship`]**
|
95
|
+
#
|
96
|
+
# * `:extra_fields`: Additional fields to send to Global Registry. Hash, Proc or Symbol. As a Hash, names are the
|
97
|
+
# keys and :type attributes are the values. Ex: `{language: :string}`. Name is a symbol and type is an
|
98
|
+
# ActiveRecord column type. As a Proc, it is passed the type and model instance, and should return a Hash.
|
99
|
+
# As a Symbol, the model should respond to this method, is passed the type, and should return a Hash.
|
100
|
+
# **[`:entity`, `:relationship`]**
|
101
|
+
#
|
102
|
+
# * `:mdm_id_column`: Column used to enable MDM tracking and set the name of the column. MDM is disabled when this
|
103
|
+
# option is nil or empty. (default: `nil`) **[`:entity`]**
|
104
|
+
#
|
47
105
|
# * `:mdm_timeout`: Only pull mdm information at most once every `:mdm_timeout`. (default: `1.minute`)
|
106
|
+
# **[`:entity`]**
|
48
107
|
#
|
49
108
|
# @api public
|
50
109
|
def global_registry_bindings(options = {})
|
51
|
-
|
110
|
+
options[:binding] ||= :entity
|
111
|
+
unless method_defined? :_global_registry_bindings_options
|
112
|
+
class_attribute :_global_registry_bindings_options
|
113
|
+
self._global_registry_bindings_options = { entity: nil, relationships: {} }
|
114
|
+
end
|
115
|
+
if options[:binding] == :entity
|
116
|
+
global_registry_bindings_entity options
|
117
|
+
elsif options[:binding] == :relationship
|
118
|
+
global_registry_bindings_relationship options
|
119
|
+
else
|
120
|
+
raise ArgumentError, ':binding option must be :entity or :relationship'
|
121
|
+
end
|
122
|
+
end
|
52
123
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
include Entity::PushRelationshipMethods
|
59
|
-
else
|
60
|
-
include Entity::EntityTypeMethods
|
61
|
-
include Entity::PushEntityMethods
|
62
|
-
end
|
124
|
+
private
|
125
|
+
|
126
|
+
def global_registry_bindings_entity(options = {})
|
127
|
+
if _global_registry_bindings_options[:entity].present?
|
128
|
+
raise '#global_registry_bindings with :entity binding called more than once.'
|
63
129
|
end
|
130
|
+
_global_registry_bindings_options[:entity] = GlobalRegistry::Bindings::Options::EntityOptionsParser.new(self)
|
131
|
+
.parse(options)
|
132
|
+
include Options unless respond_to? :global_registry_entity
|
133
|
+
global_registry_bindings_entity_includes
|
134
|
+
end
|
135
|
+
|
136
|
+
def global_registry_bindings_relationship(options = {})
|
137
|
+
options = GlobalRegistry::Bindings::Options::RelationshipOptionsParser.new(self).parse(options)
|
138
|
+
_global_registry_bindings_options[:relationships][options[:type]] = options
|
64
139
|
|
65
|
-
include
|
66
|
-
|
140
|
+
include Options unless respond_to? :global_registry_entity
|
141
|
+
global_registry_bindings_relationship_includes(options[:type])
|
67
142
|
end
|
68
143
|
|
69
|
-
|
144
|
+
def global_registry_bindings_entity_includes
|
145
|
+
include Model::Entity
|
146
|
+
if global_registry_entity.push_on.any? { |item| %i[create update].include? item }
|
147
|
+
include Model::PushEntity
|
148
|
+
end
|
149
|
+
|
150
|
+
include Model::DeleteEntity if global_registry_entity.push_on.include? :destroy
|
151
|
+
include Model::PullMdm if global_registry_entity.mdm_id_column.present?
|
152
|
+
end
|
70
153
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
154
|
+
def global_registry_bindings_relationship_includes(_type)
|
155
|
+
include Model::Relationship
|
156
|
+
include Model::PushRelationship
|
74
157
|
end
|
75
158
|
end
|
76
159
|
end
|
data/lib/global_registry_bindings/{entity/delete_entity_methods.rb → model/delete_entity.rb}
RENAMED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'global_registry_bindings/workers/
|
3
|
+
require 'global_registry_bindings/workers/delete_entity_worker'
|
4
4
|
|
5
5
|
module GlobalRegistry #:nodoc:
|
6
6
|
module Bindings #:nodoc:
|
7
|
-
module
|
8
|
-
module
|
7
|
+
module Model #:nodoc:
|
8
|
+
module DeleteEntity
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
included do
|
@@ -13,8 +13,8 @@ module GlobalRegistry #:nodoc:
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def delete_entity_from_global_registry_async
|
16
|
-
return unless
|
17
|
-
::GlobalRegistry::Bindings::Workers::
|
16
|
+
return unless global_registry_entity.id_value?
|
17
|
+
::GlobalRegistry::Bindings::Workers::DeleteEntityWorker.perform_async(global_registry_entity.id_value)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GlobalRegistry #:nodoc:
|
4
|
+
module Bindings #:nodoc:
|
5
|
+
module Model #:nodoc:
|
6
|
+
module Entity
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
def entity_attributes_to_push
|
10
|
+
entity_attributes = entity_columns_to_push.map do |name, type|
|
11
|
+
value_for_global_registry(name, type)
|
12
|
+
end.compact.to_h
|
13
|
+
entity_attributes[:client_integration_id] = id unless global_registry_entity.exclude_fields
|
14
|
+
.include?(:client_integration_id)
|
15
|
+
entity_attributes[:client_updated_at] = updated_at.to_s(:db) if respond_to?(:updated_at)
|
16
|
+
if global_registry_entity.parent_is_self?
|
17
|
+
entity_attributes[:parent_id] = global_registry_entity.parent_id_value
|
18
|
+
end
|
19
|
+
entity_attributes
|
20
|
+
end
|
21
|
+
|
22
|
+
def value_for_global_registry(name, type)
|
23
|
+
value = send(name)
|
24
|
+
return [name, value] if value.nil?
|
25
|
+
value = case type
|
26
|
+
when :datetime, :date
|
27
|
+
value.to_s(:db)
|
28
|
+
when :boolean
|
29
|
+
value ? 'true' : 'false'
|
30
|
+
else
|
31
|
+
value.to_s.strip
|
32
|
+
end
|
33
|
+
[name, value]
|
34
|
+
rescue ::NoMethodError
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def entity_columns_to_push
|
39
|
+
@columns_to_push ||= self
|
40
|
+
.class
|
41
|
+
.columns
|
42
|
+
.collect do |c|
|
43
|
+
{ c.name.underscore.to_sym => normalize_entity_column_type(c.type, c.name) }
|
44
|
+
end # rubocop:disable Style/MultilineBlockChain
|
45
|
+
.reduce(&:merge)
|
46
|
+
.reject { |k, _v| global_registry_entity.exclude_fields.include? k }
|
47
|
+
.merge(global_registry_entity.extra_fields)
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def normalize_entity_column_type(type, name)
|
53
|
+
if type.to_s == 'text'
|
54
|
+
:string
|
55
|
+
elsif name.ends_with?('_id')
|
56
|
+
:uuid
|
57
|
+
else
|
58
|
+
type
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'global_registry_bindings/workers/pull_mdm_id_worker'
|
4
|
+
|
5
|
+
module GlobalRegistry #:nodoc:
|
6
|
+
module Bindings #:nodoc:
|
7
|
+
module Model #:nodoc:
|
8
|
+
module PullMdm
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
GlobalRegistry::Bindings::Workers.mdm_worker_class(self)
|
13
|
+
after_commit :pull_mdm_id_from_global_registry_async, on: %i[create update]
|
14
|
+
end
|
15
|
+
|
16
|
+
def pull_mdm_id_from_global_registry_async
|
17
|
+
"::GlobalRegistry::Bindings::Workers::#{global_registry_entity.mdm_worker_class_name}"
|
18
|
+
.constantize .perform_async(self.class, id)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'global_registry_bindings/workers/push_entity_worker'
|
4
|
+
|
5
|
+
module GlobalRegistry #:nodoc:
|
6
|
+
module Bindings #:nodoc:
|
7
|
+
module Model #:nodoc:
|
8
|
+
module PushEntity
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
after_commit :push_entity_to_global_registry_async, on: (global_registry_entity.push_on - %i[destroy])
|
13
|
+
end
|
14
|
+
|
15
|
+
def push_entity_to_global_registry_async
|
16
|
+
::GlobalRegistry::Bindings::Workers::PushEntityWorker.perform_async(self.class, id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|