Sha256: 1e3966b047da56af93135838770e0809ffd84a4cc2d5ddbca5e2cca804b310f3

Contents?: true

Size: 1.16 KB

Versions: 19

Compression:

Stored size: 1.16 KB

Contents

module Neo4j::Mapping
  module ClassMethods
    module InitRel
      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, props = args
        rel = Neo4j::Relationship.create(type, from_node, to_node)
        wrapped_rel = super()
        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

19 entries across 19 versions & 1 rubygems

Version Path
neo4j-1.0.0.beta.27-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.26-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.25-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.24-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.23-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.22-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.21-java lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.20 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.19 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.18 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.17 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.16 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.15 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.14 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.13 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.12 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.11 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.10 lib/neo4j/mapping/class_methods/init_rel.rb
neo4j-1.0.0.beta.9 lib/neo4j/mapping/class_methods/init_rel.rb