global-registry-bindings 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'global_registry'
|
4
|
-
|
5
|
-
module GlobalRegistry #:nodoc:
|
6
|
-
module Bindings #:nodoc:
|
7
|
-
module Entity #:nodoc:
|
8
|
-
module EntityMethods
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
def entity_attributes_to_push
|
12
|
-
entity_attributes = self.class.columns_to_push.map do |name, type|
|
13
|
-
value_for_global_registry(name, type)
|
14
|
-
end.compact.to_h
|
15
|
-
entity_attributes[:client_integration_id] = id unless global_registry.exclude_fields
|
16
|
-
.include?(:client_integration_id)
|
17
|
-
entity_attributes[:client_updated_at] = updated_at.to_s(:db) if respond_to?(:updated_at)
|
18
|
-
entity_attributes[:parent_id] = global_registry.parent_id_value if global_registry.parent_is_self?
|
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
|
-
module ClassMethods
|
39
|
-
def columns_to_push
|
40
|
-
@columns_to_push ||= columns
|
41
|
-
.collect { |c| { c.name.underscore.to_sym => normalize_column_type(c.type, c.name) } }
|
42
|
-
.reduce(&:merge)
|
43
|
-
.reject { |k, _v| global_registry.exclude_fields.include? k }
|
44
|
-
.merge(global_registry.extra_fields)
|
45
|
-
end
|
46
|
-
|
47
|
-
protected
|
48
|
-
|
49
|
-
def normalize_column_type(type, name)
|
50
|
-
if type.to_s == 'text'
|
51
|
-
:string
|
52
|
-
elsif name.ends_with?('_id')
|
53
|
-
:uuid
|
54
|
-
else
|
55
|
-
type
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
module GlobalRegistry #:nodoc:
|
6
|
-
module Bindings #:nodoc:
|
7
|
-
module Options
|
8
|
-
class ClassOptions
|
9
|
-
delegate :id_column,
|
10
|
-
:mdm_id_column,
|
11
|
-
:mdm_timeout,
|
12
|
-
:type,
|
13
|
-
:push_on,
|
14
|
-
:parent_association,
|
15
|
-
:parent_association_class,
|
16
|
-
:related_association,
|
17
|
-
:related_association_class,
|
18
|
-
:parent_relationship_name,
|
19
|
-
:related_relationship_name,
|
20
|
-
:exclude_fields,
|
21
|
-
:extra_fields, to: :@options
|
22
|
-
|
23
|
-
def initialize(model_class)
|
24
|
-
@model_class = model_class
|
25
|
-
@options = OpenStruct.new model_class._global_registry_bindings_options_hash
|
26
|
-
end
|
27
|
-
|
28
|
-
def parent_class
|
29
|
-
return if parent_association.blank?
|
30
|
-
return parent_association_class if parent_association_class.present?
|
31
|
-
@model_class.reflect_on_all_associations
|
32
|
-
.detect { |a| a.name == parent_association.to_sym }
|
33
|
-
&.klass
|
34
|
-
end
|
35
|
-
|
36
|
-
def related_class
|
37
|
-
return if related_association.blank?
|
38
|
-
return related_association_class if related_association_class.present?
|
39
|
-
@model_class.reflect_on_all_associations
|
40
|
-
.detect { |a| a.name == related_association.to_sym }
|
41
|
-
&.klass
|
42
|
-
end
|
43
|
-
|
44
|
-
def parent_is_self?
|
45
|
-
parent_association.present? && parent_type == type
|
46
|
-
end
|
47
|
-
|
48
|
-
def parent_type
|
49
|
-
parent_class&.global_registry&.type
|
50
|
-
end
|
51
|
-
|
52
|
-
def related_type
|
53
|
-
related_class&.global_registry&.type
|
54
|
-
end
|
55
|
-
|
56
|
-
def mdm_worker_class_name
|
57
|
-
"Pull#{@model_class.name.tr(':', '')}MdmIdWorker"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GlobalRegistry #:nodoc:
|
4
|
-
module Bindings #:nodoc:
|
5
|
-
module Options
|
6
|
-
class InstanceOptions
|
7
|
-
delegate :id_column,
|
8
|
-
:mdm_id_column,
|
9
|
-
:mdm_timeout,
|
10
|
-
:type,
|
11
|
-
:push_on,
|
12
|
-
:parent_association,
|
13
|
-
:parent_association_class,
|
14
|
-
:related_association,
|
15
|
-
:related_association_class,
|
16
|
-
:exclude_fields,
|
17
|
-
:extra_fields,
|
18
|
-
:parent_class,
|
19
|
-
:related_class,
|
20
|
-
:parent_type,
|
21
|
-
:related_type,
|
22
|
-
:parent_relationship_name,
|
23
|
-
:related_relationship_name,
|
24
|
-
:parent_is_self?,
|
25
|
-
:mdm_worker_class_name,
|
26
|
-
to: :@class_options
|
27
|
-
|
28
|
-
def initialize(model)
|
29
|
-
@model = model
|
30
|
-
@class_options = model.class.global_registry
|
31
|
-
end
|
32
|
-
|
33
|
-
def id_value
|
34
|
-
@model.send id_column
|
35
|
-
end
|
36
|
-
|
37
|
-
def id_value=(value)
|
38
|
-
@model.send "#{id_column}=", value
|
39
|
-
end
|
40
|
-
|
41
|
-
def id_value?
|
42
|
-
@model.send "#{id_column}?"
|
43
|
-
end
|
44
|
-
|
45
|
-
def parent
|
46
|
-
@model.send(parent_association) if parent_association.present?
|
47
|
-
end
|
48
|
-
|
49
|
-
def related
|
50
|
-
@model.send(related_association) if related_association.present?
|
51
|
-
end
|
52
|
-
|
53
|
-
def parent_id_value
|
54
|
-
parent&.global_registry&.id_value
|
55
|
-
end
|
56
|
-
|
57
|
-
def related_id_value
|
58
|
-
related&.global_registry&.id_value
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'sidekiq'
|
4
|
-
require 'sidekiq-unique-jobs'
|
5
|
-
|
6
|
-
module GlobalRegistry #:nodoc:
|
7
|
-
module Bindings #:nodoc:
|
8
|
-
module Workers #:nodoc:
|
9
|
-
class PushGrEntityWorker
|
10
|
-
include Sidekiq::Worker
|
11
|
-
sidekiq_options unique: :until_and_while_executing
|
12
|
-
|
13
|
-
def perform(model_class, id)
|
14
|
-
klass = model_class.is_a?(String) ? model_class.constantize : model_class
|
15
|
-
klass.find(id).send(:push_entity_to_global_registry)
|
16
|
-
rescue ActiveRecord::RecordNotFound # rubocop:disable Lint/HandleExceptions
|
17
|
-
# If the record was deleted after the job was created, swallow it
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'GlobalRegistry::Bindings::Workers' do
|
6
|
-
describe 'PushGrEntityWorker' do
|
7
|
-
let(:user) { create(:person) }
|
8
|
-
|
9
|
-
it 'sends :push_entity_to_global_registry to the model instance' do
|
10
|
-
allow(Namespaced::Person).to receive(:push_entity_to_global_registry_async)
|
11
|
-
expect(Namespaced::Person).to receive(:find).with(user.id).and_return(user)
|
12
|
-
expect(user).to receive(:push_entity_to_global_registry)
|
13
|
-
|
14
|
-
worker = GlobalRegistry::Bindings::Workers::PushGrEntityWorker.new
|
15
|
-
worker.perform('Namespaced::Person', user.id)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'fails silently on ActiveRecord::RecordNotFound' do
|
19
|
-
allow(Namespaced::Person).to receive(:push_entity_to_global_registry_async)
|
20
|
-
expect(Namespaced::Person).to receive(:find).with(user.id).and_raise(ActiveRecord::RecordNotFound)
|
21
|
-
expect(user).not_to receive(:push_entity_to_global_registry)
|
22
|
-
|
23
|
-
worker = GlobalRegistry::Bindings::Workers::PushGrEntityWorker.new
|
24
|
-
worker.perform(Namespaced::Person, user.id)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|