Module: CruLib::GlobalRegistryMethods
- Extended by:
- ActiveSupport::Concern
- Includes:
- Async
- Defined in:
- lib/cru_lib/global_registry_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #async_push_to_global_registry(parent_id = nil, parent_type = nil, parent = nil) ⇒ Object
- #attributes_to_push(*args) ⇒ Object
- #create_in_global_registry(parent_id = nil, parent_type = nil, parent = nil) ⇒ Object
- #delete_from_global_registry ⇒ Object
-
#push_to_global_registry ⇒ Object
Define default push method.
- #update_in_global_registry(parent_id = nil, parent_type = nil, parent = nil) ⇒ Object
Methods included from Async
Instance Method Details
#async_push_to_global_registry(parent_id = nil, parent_type = nil, parent = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cru_lib/global_registry_methods.rb', line 25 def async_push_to_global_registry(parent_id = nil, parent_type = nil, parent = nil) self.class.push_structure_to_global_registry if global_registry_id begin update_in_global_registry(parent_id, parent_type, parent) rescue RestClient::ResourceNotFound self.global_registry_id = nil async_push_to_global_registry end else create_in_global_registry(parent_id, parent_type, parent) end end |
#attributes_to_push(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cru_lib/global_registry_methods.rb', line 40 def attributes_to_push(*args) unless @attributes_to_push @attributes_to_push = {} attributes_to_push['client_integration_id'] = id unless self.class.skip_fields_for_gr.include?('client_integration_id') attributes_to_push['client_updated_at'] = updated_at if respond_to?(:updated_at) attributes.each {|k, v| @attributes_to_push[k.underscore] = self.class.gr_value(k.underscore, v)} @attributes_to_push.select! {|k, v| v.present? && !self.class.skip_fields_for_gr.include?(k)} end @attributes_to_push end |
#create_in_global_registry(parent_id = nil, parent_type = nil, parent = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cru_lib/global_registry_methods.rb', line 59 def create_in_global_registry(parent_id = nil, parent_type = nil, parent = nil) entity_attributes = { self.class.global_registry_entity_type_name => attributes_to_push } if parent_type.present? entity_attributes = {parent_type => entity_attributes.merge(client_integration_id: parent.id)} GlobalRegistry::Entity.put(parent_id, {entity: entity_attributes}) else entity = GlobalRegistry::Entity.post(entity: entity_attributes) global_registry_id = entity['entity'][self.class.global_registry_entity_type_name]['id'] update_column(:global_registry_id, global_registry_id) end end |
#delete_from_global_registry ⇒ Object
14 15 16 17 18 |
# File 'lib/cru_lib/global_registry_methods.rb', line 14 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 |
#push_to_global_registry ⇒ Object
Define default push method
21 22 23 |
# File 'lib/cru_lib/global_registry_methods.rb', line 21 def push_to_global_registry async(:async_push_to_global_registry) end |
#update_in_global_registry(parent_id = nil, parent_type = nil, parent = nil) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/cru_lib/global_registry_methods.rb', line 51 def update_in_global_registry(parent_id = nil, parent_type = nil, parent = nil) if parent_type create_in_global_registry(parent_id, parent_type, parent) else GlobalRegistry::Entity.put(global_registry_id, {entity: attributes_to_push}) end end |