Sha256: 1c6781579e5bb315232db263e036ff51b518e53793bc48f9b5f2f94dd92dace4

Contents?: true

Size: 1.96 KB

Versions: 21

Compression:

Stored size: 1.96 KB

Contents

module Neo4j
  module Wrapper
    module RelationshipMixin
      module ClassMethods

        # Creates a relationship between given nodes.
        #
        # You can use two callback method to initialize the relationship
        # init_on_load:: this method is called when the relationship is loaded from the database
        # init_on_create:: called when the relationship is created, will be provided with the same argument as the new method
        #
        # @param [String, Symbol] type the type of the relationships
        # @param [Neo4j::Node, Neo4j::NodeMixin] from_node create relationship from this node
        # @param [Neo4j::Node, Neo4j::NodeMixin] to_node create relationship to this node
        # @param [Hash] props optional hash of properties to initialize the create relationship with
        # @see http://rdoc.info/github/andreasronge/neo4j-core/master/Neo4j/Relationship Neo4j::Relationship
        def new(type, from_node, to_node, *props)
          rel = Neo4j::Relationship.create(type, from_node, to_node)
          wrapped_rel = super()
          Neo4j::IdentityMap.add(rel, wrapped_rel)
          wrapped_rel.init_on_load(rel)
          wrapped_rel.init_on_create(type, from_node, to_node, *props)
          wrapped_rel
        end

        alias_method :create, :new

        # Loads a wrapped relationship from the database given a neo id.
        # @param [#to_i, nil] neo_id
        # @raise an exception if the loaded node/relationship is not of the same kind as this class.
        # @return [Object, nil] If the node does not exist it will return nil otherwise the loaded relationship or wrapped relationship.
        def load_entity(neo_id)
          node = Neo4j::Relationship.load(neo_id)
          return nil if node.nil?
          return node if node.class == Neo4j::Relationship
          raise "Expected loaded node #{neo_id} to be of type #{self} but it was #{node.class}" unless node.kind_of?(self)
          node
        end

      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
neo4j-wrapper-2.3.0-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.2.4-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.2.3-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.2.1-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.2.0-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.2.0.rc1-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.1.0-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.0.1-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.0.0-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.0.0.rc2-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-2.0.0.rc1-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.11-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.10-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.9-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.8-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.7-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.6-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.5-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.4-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb
neo4j-wrapper-0.0.3-java lib/neo4j-wrapper/relationship_mixin/class_methods.rb