Labels

Provides a mapping between neo4j labels and Ruby classes

Constants

  • WRAPPED_CLASSES
  • MODELS_FOR_LABELS_CACHE
  • MODELS_TO_RELOAD

Methods

._wrapped_classes

def self._wrapped_classes
  WRAPPED_CLASSES
end
#add_label

adds one or more labels

def add_label(*label)
  @_persisted_obj.add_label(*label)
end

.add_wrapped_class

def self.add_wrapped_class(model)
  _wrapped_classes << model
end

.clear_wrapped_models

def self.clear_wrapped_models
  WRAPPED_CLASSES.clear
  MODELS_FOR_LABELS_CACHE.clear
  Neo4j::Node::Wrapper::CONSTANTS_FOR_LABELS_CACHE.clear
end

#labels

def labels
  @_persisted_obj.labels
end
.model_for_labels

Finds an appropriate matching model given a set of labels which are assigned to a node

def self.model_for_labels(labels)
  return MODELS_FOR_LABELS_CACHE[labels] if MODELS_FOR_LABELS_CACHE[labels]

  models = WRAPPED_CLASSES.select do |model|
    (model.mapped_label_names - labels).size == 0
  end

  MODELS_FOR_LABELS_CACHE[labels] = models.max do |model|
    (model.mapped_label_names & labels).size
  end
end
#remove_label

Removes one or more labels Be careful, don’t remove the label representing the Ruby class.

def remove_label(*label)
  @_persisted_obj.remove_label(*label)
end