module Neo4j::ActiveNode::Labels
Provides a mapping between neo4j labels and Ruby classes
Constants
- MODELS_FOR_LABELS_CACHE
- WRAPPED_CLASSES
Public Class Methods
_wrapped_classes()
click to toggle source
# File lib/neo4j/active_node/labels.rb 64 def self._wrapped_classes 65 WRAPPED_CLASSES 66 end
add_wrapped_class(model)
click to toggle source
# File lib/neo4j/active_node/labels.rb 68 def self.add_wrapped_class(model) 69 _wrapped_classes << model 70 end
clear_wrapped_models()
click to toggle source
# File lib/neo4j/active_node/labels.rb 87 def self.clear_wrapped_models 88 MODELS_FOR_LABELS_CACHE.clear 89 Neo4j::NodeWrapping::CONSTANTS_FOR_LABELS_CACHE.clear 90 end
model_for_labels(labels)
click to toggle source
Finds an appropriate matching model given a set of labels which are assigned to a node
# File lib/neo4j/active_node/labels.rb 74 def self.model_for_labels(labels) 75 labels.sort! 76 return MODELS_FOR_LABELS_CACHE[labels] if MODELS_FOR_LABELS_CACHE[labels] 77 78 models = WRAPPED_CLASSES.select do |model| 79 (model.mapped_label_names - labels).empty? 80 end 81 82 MODELS_FOR_LABELS_CACHE[labels] = models.max_by do |model| 83 (model.mapped_label_names & labels).size 84 end 85 end
Public Instance Methods
add_label(*_labels)
click to toggle source
Remove this method in 9.0.0
# File lib/neo4j/active_node/labels.rb 45 def add_label(*_labels) 46 fail 'add_label has been removed in favor of `add_labels`' 47 end
add_labels(*labels)
click to toggle source
adds one or more labels @see Neo4j-core
# File lib/neo4j/active_node/labels.rb 36 def add_labels(*labels) 37 labels.inject(query_as(:n)) do |query, label| 38 query.set("n:`#{label}`") 39 end.exec 40 @_persisted_obj.labels.concat(labels) 41 @_persisted_obj.labels.uniq! 42 end
labels()
click to toggle source
@return the labels @see Neo4j-core
# File lib/neo4j/active_node/labels.rb 25 def labels 26 @_persisted_obj.labels 27 end
remove_label(*_labels)
click to toggle source
Remove this method in 9.0.0
# File lib/neo4j/active_node/labels.rb 60 def remove_label(*_labels) 61 fail 'remove_label has been removed in favor of `remove_labels`' 62 end
remove_labels(*labels)
click to toggle source
Removes one or more labels Be careful, don't remove the label representing the Ruby class. @see Neo4j-core
# File lib/neo4j/active_node/labels.rb 52 def remove_labels(*labels) 53 labels.inject(query_as(:n)) do |query, label| 54 query.remove("n:`#{label}`") 55 end.exec 56 labels.each(&@_persisted_obj.labels.method(:delete)) 57 end