module ActiveGraph::Node::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/active_graph/node/labels.rb
54 def self._wrapped_classes
55   WRAPPED_CLASSES
56 end
add_wrapped_class(model) click to toggle source
   # File lib/active_graph/node/labels.rb
58 def self.add_wrapped_class(model)
59   _wrapped_classes << model
60 end
clear_wrapped_models() click to toggle source
   # File lib/active_graph/node/labels.rb
77 def self.clear_wrapped_models
78   MODELS_FOR_LABELS_CACHE.clear
79   ActiveGraph::NodeWrapping::CONSTANTS_FOR_LABELS_CACHE.clear
80 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/active_graph/node/labels.rb
64 def self.model_for_labels(labels)
65   labels.sort!
66   return MODELS_FOR_LABELS_CACHE[labels] if MODELS_FOR_LABELS_CACHE[labels]
67 
68   models = WRAPPED_CLASSES.select do |model|
69     (model.mapped_label_names - labels).empty?
70   end
71 
72   MODELS_FOR_LABELS_CACHE[labels] = models.max_by do |model|
73     (model.mapped_label_names & labels).size
74   end
75 end

Public Instance Methods

add_labels(*labels) click to toggle source

adds one or more labels @see ActiveGraph::Core

   # File lib/active_graph/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 ActiveGraph::Core

   # File lib/active_graph/node/labels.rb
25 def labels
26   @_persisted_obj.labels
27 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 ActiveGraph::Core

   # File lib/active_graph/node/labels.rb
47 def remove_labels(*labels)
48   labels.inject(query_as(:n)) do |query, label|
49     query.remove("n:`#{label}`")
50   end.exec
51   labels.each(&@_persisted_obj.labels.method(:delete))
52 end