Sha256: a0b8b9f7436104eeb66c0b0716faf5095555d09ce0f361f583144b08d04c8104

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

module Neo4j
  module RelationshipMixin
    module ClassMethods
      def load_wrapper(rel)
        wrapped_rel = self.orig_new
        wrapped_rel.init_on_load(rel)
        wrapped_rel
      end


      # 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
      #
      # ==== Parameters (when creating a new relationship in db)
      # type:: the key and value to be set
      # from_node:: create relationship from this node
      # to_node:: create relationship to this node
      # props:: optional hash of properties to initialize the create relationship with
      #
      def new(*args)
        type, from_node, to_node = args
        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(*args)
        wrapped_rel
      end

      alias_method :create, :new
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
neo4j-2.0.0.alpha.5-java lib/neo4j/relationship_mixin/class_methods.rb
neo4j-2.0.0.alpha.4-java lib/neo4j/relationship_mixin/class_methods.rb
neo4j-2.0.0.alpha.3-java lib/neo4j/relationship_mixin/class_methods.rb
neo4j-1.3.1-java lib/neo4j/relationship_mixin/class_methods.rb
neo4j-1.3.0-java lib/neo4j/relationship_mixin/class_methods.rb
neo4j-1.2.6-java lib/neo4j/relationship_mixin/class_methods.rb
neo4j-1.2.5-java lib/neo4j/relationship_mixin/class_methods.rb