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(*label) ⇒ Object
adds one or more labels.
-
#labels ⇒ Object
The labels.
-
#remove_label(*label) ⇒ Object
Removes one or more labels Be careful, don’t remove the label representing the Ruby class.
Methods included from ActiveSupport::Concern
Methods included from Reloading
Class Method Details
._wrapped_classes ⇒ Object
45 46 47 |
# File 'lib/neo4j/active_node/labels.rb', line 45 def self._wrapped_classes WRAPPED_CLASSES end |
.add_wrapped_class(model) ⇒ Object
49 50 51 |
# File 'lib/neo4j/active_node/labels.rb', line 49 def self.add_wrapped_class(model) _wrapped_classes << model end |
.clear_wrapped_models ⇒ Object
67 68 69 70 |
# File 'lib/neo4j/active_node/labels.rb', line 67 def self.clear_wrapped_models MODELS_FOR_LABELS_CACHE.clear Neo4j::Node::Wrapper::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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/neo4j/active_node/labels.rb', line 55 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_by do |model| (model.mapped_label_names & labels).size end end |
Instance Method Details
#add_label(*label) ⇒ Object
adds one or more labels
34 35 36 |
# File 'lib/neo4j/active_node/labels.rb', line 34 def add_label(*label) @_persisted_obj.add_label(*label) end |
#labels ⇒ Object
Returns the labels.
23 24 25 |
# File 'lib/neo4j/active_node/labels.rb', line 23 def labels @_persisted_obj.labels end |
#remove_label(*label) ⇒ Object
Removes one or more labels Be careful, don’t remove the label representing the Ruby class.
41 42 43 |
# File 'lib/neo4j/active_node/labels.rb', line 41 def remove_label(*label) @_persisted_obj.remove_label(*label) end |