module CruLib::GlobalRegistryMethods

Public Instance Methods

async_push_to_global_registry(parent_id = nil, parent_type = nil, parent = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source

Define default push method

# 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) click to toggle source
# 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