Module: CruLib::GlobalRegistryRelationshipMethods
- Extended by:
- ActiveSupport::Concern
- Includes:
- GlobalRegistryMethods
- Defined in:
- lib/cru_lib/global_registry_relationship_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #async_push_to_global_registry ⇒ Object
- #attributes_to_push(relationship_name: nil, related_name: nil, related_object: nil, base_object: nil) ⇒ Object
- #create_in_global_registry(base_object, relationship_name) ⇒ Object
-
#delete_from_global_registry ⇒ Object
TODO - deleting a relationship is different.
Methods included from GlobalRegistryMethods
#push_to_global_registry, #update_in_global_registry
Methods included from Async
Instance Method Details
#async_push_to_global_registry ⇒ Object
6 7 8 |
# File 'lib/cru_lib/global_registry_relationship_methods.rb', line 6 def async_push_to_global_registry super end |
#attributes_to_push(relationship_name: nil, related_name: nil, related_object: nil, base_object: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cru_lib/global_registry_relationship_methods.rb', line 20 def attributes_to_push(relationship_name: nil, related_name: nil, related_object: nil, base_object: nil) if global_registry_id attributes_to_push = super attributes_to_push else { "#{relationship_name}:relationship" => { client_integration_id: id, => .global_registry_id }, client_integration_id: base_object.id } end end |
#create_in_global_registry(base_object, relationship_name) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cru_lib/global_registry_relationship_methods.rb', line 37 def create_in_global_registry(base_object, relationship_name) entity = GlobalRegistry::Entity.put( base_object.global_registry_id, entity: { base_object.class.global_registry_entity_type_name => attributes_to_push(base_object: base_object) } ) base_object_id = entity['entity'][base_object.class.global_registry_entity_type_name]['id'] entity = GlobalRegistry::Entity.find(base_object_id)['entity'] global_registry_id = Array.wrap( entity[base_object.class.global_registry_entity_type_name]["#{relationship_name}:relationship"] ).detect do |hash| cid = hash['client_integration_id'] cid = cid['value'] if cid.is_a?(Hash) cid == id.to_s end['relationship_entity_id'] update_column(:global_registry_id, global_registry_id) update_in_global_registry end |
#delete_from_global_registry ⇒ Object
TODO - deleting a relationship is different.
11 12 13 14 15 |
# File 'lib/cru_lib/global_registry_relationship_methods.rb', line 11 def delete_from_global_registry if global_registry_id Sidekiq::Client.enqueue(self.class, nil, :async_delete_from_global_registry, global_registry_id) end end |