Module: Neo4j::Wrapper

Extended by:
Wrapper
Included in:
Wrapper
Defined in:
lib/neo4j-wrapper/class_methods.rb,
lib/neo4j-wrapper/find.rb,
lib/neo4j-wrapper/wrapper.rb,
lib/neo4j-wrapper/version.rb,
lib/neo4j-wrapper/rule/rule.rb,
lib/neo4j-wrapper/has_n/nodes.rb,
lib/neo4j-wrapper/equal/equal.rb,
lib/neo4j-wrapper/has_n/decl_rel.rb,
lib/neo4j-wrapper/rule/rule_node.rb,
lib/neo4j-wrapper/rule/functions/sum.rb,
lib/neo4j-wrapper/rule/class_methods.rb,
lib/neo4j-wrapper/rule/functions/size.rb,
lib/neo4j-wrapper/rule/event_listener.rb,
lib/neo4j-wrapper/has_n/class_methods.rb,
lib/neo4j-wrapper/node_mixin/delegates.rb,
lib/neo4j-wrapper/node_mixin/initialize.rb,
lib/neo4j-wrapper/rule/instance_methods.rb,
lib/neo4j-wrapper/has_n/instance_methods.rb,
lib/neo4j-wrapper/rule/functions/function.rb,
lib/neo4j-wrapper/properties/class_methods.rb,
lib/neo4j-wrapper/node_mixin/class_methods.rb,
lib/neo4j-wrapper/properties/instance_methods.rb,
lib/neo4j-wrapper/relationship_mixin/delegates.rb,
lib/neo4j-wrapper/relationship_mixin/initialize.rb,
lib/neo4j-wrapper/relationship_mixin/class_methods.rb

Overview

Responsible for loading the correct Ruby wrapper class for the Neo4j Entity

Defined Under Namespace

Modules: ClassMethods, Equal, Find, HasN, NodeMixin, Property, RelationshipMixin, Rule

Constant Summary

VERSION =
'2.3.0'

Instance Method Summary collapse

Instance Method Details

#to_class(class_name) ⇒ Class

Returns the class corresponding to the given name

Parameters:

  • class_name (String)

    the name we want the Class for

Returns:

  • (Class)

    the class corresponding to the given name



24
25
26
# File 'lib/neo4j-wrapper/wrapper.rb', line 24

def to_class(class_name)
  class_name.split("::").inject(Kernel) { |container, name| container.const_get(name.to_s) }
end

#wrapper(entity) ⇒ Object

This method is used when loading Neo4j::Node objects

Reads the _classname property and tries to load the ruby class. The Neo4j::Core gem will use this method, because the following:

Neo4j::Node.wrapper_proc=method(:wrapper)

Parameters:

  • entity (Neo4j::Node, Neo4j:Relationship)

    the entity which might be wrapped

Returns:

  • (Object)

    a Ruby class wrapping the given entity

See Also:

  • Core::Wrapper.wrapper_proc=


13
14
15
16
17
18
19
20
# File 'lib/neo4j-wrapper/wrapper.rb', line 13

def wrapper(entity)
  return entity unless entity.property?(:_classname)
  existing_instance = Neo4j::IdentityMap.get(entity)
  return existing_instance if existing_instance
  new_instance = to_class(entity[:_classname])._load_wrapper(entity)
  Neo4j::IdentityMap.add(entity, new_instance)
  new_instance
end