Module: Neo4j::ActiveNode::Labels

Extended by:
ActiveSupport::Concern
Includes:
Index, Reloading
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

Reloading::MODELS_TO_RELOAD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

class_methods

Methods included from Reloading

reload_models!

Class Method Details

._wrapped_classesObject



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_modelsObject



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

See Also:

  • Neo4j-core


34
35
36
# File 'lib/neo4j/active_node/labels.rb', line 34

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

#labelsObject

Returns the labels.

Returns:

  • the labels

See Also:

  • Neo4j-core


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.

See Also:

  • Neo4j-core


41
42
43
# File 'lib/neo4j/active_node/labels.rb', line 41

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