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