Sha256: 2fd32cf4447942a352fdf06f4438e50013d9cd78741ea9ffe746f2c416f2cf14

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

module Neo4j::Mapping
  module ClassMethods
    module InitNode

      def load_wrapper(node)
        wrapped_node = self.orig_new
        wrapped_node.init_on_load(node)
        wrapped_node
      end


      # Creates a new node or loads an already existing Neo4j node.
      #
      # You can use two callback method to initialize the node
      # init_on_load:: this method is called when the node is loaded from the database
      # init_on_create:: called when the node is created, will be provided with the same argument as the new method
      #
      #
      # Does
      # * sets the neo4j property '_classname' to self.class.to_s
      # * creates a neo4j node java object (in @_java_node)
      #
      # If you want to provide your own initialize method you should instead implement the
      # method init_on_create method.
      #
      # === Example
      #
      #   class MyNode
      #     include Neo4j::NodeMixin
      #
      #     def init_on_create(name, age)
      #        self[:name] = name
      #        self[:age] = age
      #     end
      #   end
      #
      #   node = MyNode.new('jimmy', 23)
      #
      def new(*args)
        node = Neo4j::Node.create
        wrapped_node = super()
        wrapped_node.init_on_load(node)
        wrapped_node.init_on_create(*args)
        wrapped_node
      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_node.rb
neo4j-1.0.0.beta.26-java lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.25-java lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.24-java lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.23-java lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.22-java lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.21-java lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.20 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.19 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.18 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.17 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.16 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.15 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.14 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.13 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.12 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.11 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.10 lib/neo4j/mapping/class_methods/init_node.rb
neo4j-1.0.0.beta.9 lib/neo4j/mapping/class_methods/init_node.rb