Sha256: 3d122400bfc9705230031aa8f27aa742d8d3ebaddc53cbffc32c8aceb61c4550
Contents?: true
Size: 1.78 KB
Versions: 4
Compression:
Stored size: 1.78 KB
Contents
module N4j::Node autoload :AutoRelate, 'n4j/auto_relate' autoload :Index, 'n4j/index' extend ActiveSupport::Concern included do include AutoRelate include Index # include N4j::Entity end module ClassMethods def find(n) find_by_node_id(n) end def find_by_node_id(n) find_by_path("/node/#{n}") end def find_by_path(path) path.sub!(N4j.neo4j_url_prefix,'') result = N4j.batch([{:to => path, :method => 'GET'}]) new(result.first['body']) end def service_root find_by_node_id(0) end end def initialize(hsh) super(hsh) unless N4j.neo4j_hash?(hsh) self.data = HashWithIndifferentAccess.new.merge(hsh) end end def create_path '/node' end def body_hash data end def dependent relationships end def connected_unsaved new_relationships end def post_save clear_new_relationships! end def relationships(direction = 'all_relationships', types = [], clear_cache = false) @relationship_cache ||= {} if persisted? path = from_neo4j_relative[direction] + '/' + [types].flatten.join('&') @relationship_cache.delete(path) if clear_cache @relationship_cache[path] ||= GenericRelationship.find_by_node_path(path) else [] end end def entity_type 'node' end def traverse(opts = {}) # Started this approach, stoppedto investigate Cypher defaults = {:start => path, :instantiate_with => self.class } N4j::Traversal.new(:start => path) end def cypher(opts = {}) defaults = {:start => self, :instantiate_with => self.class} N4j::Cypher.new(defaults.merge(opts)) end def new_relationships @new_relationships ||= [] end def clear_new_relationships! @new_relationships = [] end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
n4j-0.0.1.6.3 | lib/n4j/node.rb |
n4j-0.0.1.6.1 | lib/n4j/node.rb |
n4j-0.0.1.6 | lib/n4j/node.rb |
n4j-0.0.1.5 | lib/n4j/node.rb |