Module: N4j::Node

Extended by:
ActiveSupport::Concern
Included in:
GenericNode
Defined in:
lib/n4j/node.rb

Defined Under Namespace

Modules: AutoRelate, ClassMethods

Instance Method Summary collapse

Instance Method Details

#body_hashObject



41
42
43
# File 'lib/n4j/node.rb', line 41

def body_hash
  data
end

#clear_new_relationships!Object



87
88
89
# File 'lib/n4j/node.rb', line 87

def clear_new_relationships!
  @new_relationships = []
end

#connected_unsavedObject



49
50
51
# File 'lib/n4j/node.rb', line 49

def connected_unsaved
  new_relationships
end

#create_pathObject



37
38
39
# File 'lib/n4j/node.rb', line 37

def create_path
  '/node'
end

#cypher(opts = {}) ⇒ Object



78
79
80
81
# File 'lib/n4j/node.rb', line 78

def cypher(opts = {})
  defaults = {:start => self}
  N4j::Cypher.new(defaults.merge(opts))
end

#dependentObject



45
46
47
# File 'lib/n4j/node.rb', line 45

def dependent
  relationships
end

#entity_typeObject



68
69
70
# File 'lib/n4j/node.rb', line 68

def entity_type
  'node'
end

#initialize(hsh) ⇒ Object



30
31
32
33
34
35
# File 'lib/n4j/node.rb', line 30

def initialize(hsh)
  super(hsh)
  unless N4j.neo4j_hash?(hsh)
    self.data = hsh.dup
  end
end

#new_relationshipsObject



83
84
85
# File 'lib/n4j/node.rb', line 83

def new_relationships
  @new_relationships ||= []
end

#post_saveObject



53
54
55
# File 'lib/n4j/node.rb', line 53

def post_save
  clear_new_relationships!
end

#relationships(direction = 'all_relationships', types = [], clear_cache = false) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/n4j/node.rb', line 57

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

#traverse(opts = {}) ⇒ Object



72
73
74
75
76
# File 'lib/n4j/node.rb', line 72

def traverse(opts = {})
  # Started this approach, stoppedto investigate Cypher
  defaults = {:start => path, :instantiate_with => self.class }
  N4j::Traversal.new(:start => path)
end